What is R ?

R Programming is a language used for data analysis and data visualization.

As Data is becoming huge we need an important and reliable tool to operate and manage the data,so here we introduce R.

But why to choose R over other software ?

R is an open source software and is reliable with much flexibility .R is designed in a way that overcome the problems that is faced in data management specially very large data.

1. How we import data in R?

     1.1  Import Data from Excel in to R : Csv File , Tab Delimited File , Xlsx File

  • Csv File :
BodyCap Age Height Smoke Gender
6.475 6 62.1 no male
10.152 18 74.7 yes female
9.55 16 69.7 no female
11.125 14 71 no male
4.8 5 5.99 no male
6.225 11 63.3 no female
4.95 8 39.2 no male

 

Save this excel file with file type CSV( Comma Delimited)

Open RStudio and to import this file type the following command

 

Data1<-read.table(file.choose(),header=TRUE,sep= “  “)

OR

Data1<-read.csv(file.choose(),header=TRUE)

 

With file.choose() a tab is open and then you can choose your file without typing the complete path

Header= TRUE: shows the first row contains variables

sep = “  “ : shows the numeric are separated by space

 

  • Tab delimited File:

Save the excel file with file type Text(Tab Delimited File)

Open RStudio and to import the file type the following command:

Data1<-read.table(file.choose(),header=TRUE,sep= “ \ t “)

OR

Data1<-read.delim(file.choose(),header=TRUE)

what happen if you forget the arguments?

Do Not Worry! Type ctrl+Space,this will list the arguments.

  • XLSV File: Save your Excel file in XLSV type an dopen RStudio

                    Install xlsv package using the following command

                    install.packages(“xlsv”) → Package will be installed for life until you uninstall it

Then how to import this file?

Type the following command:

                            Data1<-read.xlsv(file.choose(),sheetname= “Name of Your Excel Sheet”)

   1.2  Importing Data from SPSS,SAS,STATA

  • SPSS: To import the file from SPSS type the following command after importing the Hmisc package

Steps

  1. #install package: install.packages(“Hmisc”)
  2. #load library :require(Hmisc)
  3. #import data: Data1<- spss.get(file.choose(), use.value.labels=TRUE)
  4. #see data: Data1
  • SAS: To import the file from SAS type the following command after importing the Hmisc package

 

Steps

a) #install package: install.packages(“Hmisc”)

b) #load library :require(Hmisc)

c) #import data: Data1<- sasxport.get(file.choose())

d) #see data: Data1

  • STATA: To import the file from SAS type the following command after importing the foreign package

 

Steps

 

 a) #install package: install.packages(“foreign”)

b) #load library :require(foreign)

c) #import data: Data1< read.dta(file.choose()

d) #see data: Data1

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s