This introductory post on R software is just enough to get you started so that the other posts on R don't need to repeat the same information at the beginning each time. It was developed in collaboration with Thomas Pienkowski.
What is R?
R is a free, open source software that uses a command
interface to interact with the user.
Outputs include strings of text within the command line as well as
graphical outputs in a separate window.
It has some basic commands that are supplemented by packages developed
by third parties and individually downloaded and installed, like plugins or
apps.
What is an R Session?
Each session in the R Console starts from the
beginning. Strings of commands are
stored in R studio or some other separate program. A session ends when you close the R window. This means that each time you restart R, you
must re-attach any packages and insert the string of commands that you have
worked out thus far. This may seem like
a major pain, but actually much of the time in R is spent working out the
commands, not entering them.
Packages:
Packages exist in one of three sequential states in relation
to your use of R:
1.
A developed package that is not yet on your
computer, but exists
2.
A package that has been installed on your
computer and is available to be attached during each session
3.
A package that has been attached to your
particular session and is ready for use
Commands:
Commands are typed by you in the command line. A command line always starts with > and
then has a command name followed by parameters enclosed in ( ) and separated by
commas. Names are sometimes enclosed in
" ".
For example:
> plot ( "x", height = 10, width = 10)
Hit "return" to enter a command. The program will read the command and then do
one of four things:
1.
Return requested information below the command
line, which may involved performing a task or calculation
2.
Perform a task visualized in another window
(usually a graph)
3.
Perform a task, but not return any information
in the command line
4.
Return an error message
To go through commands you have previously typed in your
session, use the up arrow.
To create your own "uniquename" for a data set
(this is called an assignment), or even for a command performed to a data set:
> uniquename = command
Note that R commands are case-sensitive, so X is different
from x. Spaces within the command line
do not matter.
Commands can also pull information from a subset of an
object or dataset. To do this, use [
] For example, in the case of a matrix
(or spreadsheet or table) of data called X, typing: > X[1,2] will return the
data in the first row, second column.
Helpful Commands:
To get help on the function of a command X:
> ??X
To return command names that contain X:
> apropos("X")
To see the color options:
> colors()
To see installed packages:
> library()
To install packages, use the dropdown menu called
"Packages and Data," and select "Package Installer," or use
this command to install package X:
> install.packages("X")
To see a list of the objects in your current session:
> ls()
To view basic information on a dataset X:
>summary(X)Resources:
Download R to install on your computer.
Good self-learning introduction:
A place to explore packages:
Where to find packages to install:
To find packages that help R interface with other software,
such as Google Earth:
PDF color chart:
What is your favorite R resource? Feel free to share it below.
No comments:
Post a Comment