Wednesday, October 16, 2013

Getting Started with R ( simple first 5 steps)

Here are a few steps that can get you started with R. This is assuming you have installed R on your computer. If you haven't, download it from here (http://www.r-project.org/).

Before you do anything else, you need to define the working directory for R. By default, R will have its own working directory. It is a good idea to change the working  directory based on the project you are working on.

1. Check the current working directory:
> getwd()

 Change the current working directory:
> setwd(C:\Users\ABC)

Note: Notice the type of slashes used in writing the directory. Using a different slash is a common issue.

2. Load your data file:
1. Although you can load your file in various formats, I would recommend creating a csv file format of your data.
2. Place the file in the working directory. You can place it anywhere else on the computer as well but in that case, you have to enter the full location of the file.

> a = read.csv("file.csv")

This is assigning the name 'a' for your file in R.

3. Get column names:

> names(a)

4. Know the data type (gives you the structure of your dataset):

> str(a)

5. Summary of the dataset:

> summary(a) 

At any point, if you feel the need of knowing more about the command you are using, you can use help in R.
> ?command
e.g. > ?read.csv

3 comments: