Data analysis in R | How to import data into R - Statistical Aid

 


Importing data from SPSS to R

The importing procedure of data set into R is following-
  •  open R programm
  •  open a new script
  •  write the following code

library(foreign)
Data_set <- read.spss("data set location/data set name", use.value.label=TRUE, to.data.frame=TRUE)
Data_set

Importing data from Stata to R

# input Stata file
library(foreign)
mydata <- read.dta("c:/mydata.dta")

Importing data from Excel to R

# first row contains variable names
library(xlsx)
mydata <- read.xlsx("c:/myexcel.xlsx", 1)

# read in the worksheet named mysheet
mydata <- read.xlsx("c:/myexcel.xlsx", sheetName = "mysheet")

Importing data from csv file to R

# first row contains variable names, comma is separator
# assign the variable id to row names
# note the / instead of \ on mswindows systems

mydata <- read.table("c:/mydata.csv", header=TRUE,
   sep=",", row.names="id")

Importing data from SAS to R

# save SAS dataset in trasport format
libname out xport 'c:/mydata.xpt';
data out.mydata;
set sasuser.mydata;
run;

# in R
library(Hmisc)
mydata <- sasxport.get("c:/mydata.xpt")
# character variables are converted to R factors


1. open R software





2. Open new script







3. Type the above code.








4. Run the code.









For step by step procedure check this video.




Post a Comment

0 Comments