Skip to main content


Showing posts from March, 2013

R: Importing Data

There are number of ways in importing data into R, and several formats are available,
From Excel to R;from SPSS to R; and,from Stata to R, and more here. In this post, we are going to talk about importing common data format that we often encounter, such as Excel and Text data. Most of the data are saved in MS Excel, and the best way to import this is to save this in CSV format, below is the procedure: Open your Excel data;go to File > Save As or press Ctrl+Shift+S;name this with anything you want, say "Data". Then before clicking Save, make sure to change the File Format to Comma Delimited Text and better set the directory to My Documents folder, for Windows. when saved, this file will have a name "Data.csv". Now open R, and run the following

The argument header = TRUE tells R that the first row of the data are the labels of every column. If set to FALSE, means the first row of the data are not the labels, but are considered as data points.

R: How to Encode your Data?

Every experiment starts with data, so the question is "how do you enter your data into R?". Well there are many ways to do that, but for this post, we will only consider the two functions below:
The concatenate, c; and,the data.frame functions. The concatenate function, c, is use for combining data points into single numeric R object, known as the vector. The usage of this function is simply

Where ... is the objects to be concatenated. Run ?c, for description of the second argument. Let's try an example,

What happened here is that, we defined a new object, vec1, into the workspace. We can then start manipulating the entries, say using the summary,

For dispersion, try this,

What about the data.frame function? If the first function combines data points into a single vector, data.frame from the name itself constructs a frame of data points. Here is an example,

What we did here is we defined two R objects, the weights and volunteers, then we combine the two into a table li…

R: Download and Installation in Ubuntu

There are two ways to install R in Ubuntu. One is through the terminal, and the other is through the Ubuntu Software Center.
Through the Terminal
Press Ctrl+Alt+T to open the Terminal;then execute sudo apt-get update; after that,run sudo apt-get install r-base; To run R, execute R in the Terminal (see the picture below).

Through Ubuntu Software Center
Open Ubuntu Software Center;search for r-base;and click Install;then run R by executing R in the Terminal. Working in the Terminal would be inconvenient, so I suggest downloading a user-friendly interface. For example in Ubuntu, I recommend using RStudio IDE or RKWard KDE.

R: Download and Installation in Windows

R installer is available on CRAN. To download the software, go to the site and do the following: click Download R for Windows; then go to install R for the first time in the base subdirectory; and finally download the latest version of R for windows.

Now to install R, watch the video below.