R Installation
(1) Go to the R project site; (2) On the left bar menu, click CRAN; (3) Select any "mirrors" you like (a mirror geographically close to Lawrence will be a good choice); (4) Choose your machine type: Linux; MacOS X; or Windows; (5) Download "base" program; (6) Install R in your machine.
Or simply
- Windows Users: Download R-2.15.0-win.exe and install it in your PC. Follow the default setting. Installation instructions can be found here.
- Mac Users: Download R-2.15.0.pkg and install it in your machine. Follow the default setting. Installation instructions for Mac are here.
- Linux Users: Check here. Note that it will be easier to find pre-compiled packages thru linux repositories. To install R program in your Linux machine, type the following command in your terminal:
> sudo apt-get install r-base r-base-dev
R as a Calculator
Start R on your system. Enter the expression 2+2, then press the Enter key. The result follows.
> 2+2 [1] 4
Square and Square root can be done as follows;.
> 3^2 [1] 9 > sqrt(3) [1] 1.732051
natural log and exponential:
> log(3) [1] 1.098612 > exp(3) [1] 20.08554
factorial function. Let's try 10! (Note that 10! is equal to 10*9*8*7*6*5*4*3*2*1.):
> factorial(10) [1] 3628800
Data Input
1. Data Input with "variable name <- c()" command
Let's add 3, 8, 9, 10, 6 for a variable x. Use "variable name <- c()" command
> x <- c(3, 8, 9, 10, 6) > x [1] 3 8 9 10 6
This time, let's add a variable y as 5, 12, 18, 23, 29.
> y <- c(5, 12, 18, 23, 29) > y [1] 5 12 18 23 29
We can add x and y:
> x+y [1] 8 20 27 33 35
To combine x and y into a dataset named "dataxy" (The dataset name can be anything you like.)
> dataxy<-data.frame(x, y)
2. Data input using the R data editor
You can input your data using the R data editor:
> mydata <- edit(as.data.frame(NULL))
Then type your data in the edit window, and:
> attach(mydata)