Data Frames
Data frame is similar to datasets SAS, SPSS and Stata. The data frame is created with R.
Data<- data.frame(col1, col2,col3,..), where col1,col2....... are column vectors. Data frames are close to what the analyst typically think of as data sets. There are several ways to identify the elements of a data frame. Here using the student data as a data frame.
> studentID <- c(1, 2, 3, 4)
> age <- c(25, 34, 28, 32)
> score <- c("Type1", "Type2", "Type1", "Type1")
> status <- c("Poor", "Improved", "Excellent", "Poor")
> studentdata <- data.frame(studentID, age, score, status)
> studentdata
studentID age score status
1 1 25 Type1 Poor
2 2 34 Type2 Improved
3 3 28 Type1 Excellent
4 4 32 Type1 Poor
> studentdata[1:2]
studentID age
1 1 25
2 2 34
3 3 28
4 4 32
> studentdata[c("score", "status")]
score status
1 Type1 Poor
2 Type2 Improved
3 Type1 Excellent
4 Type1 Poor
> studentdata$age
[1] 25 34 28 32
> table(studentdata$score, studentdata$status)
Excellent Improved Poor
Type1 1 0 2
Type2 0 1 0
studentdata <- data.frame(studentID, age, score, status,
+ row.names=studentID)
Importing data from EXCEL
download and install the RODBC package
> install.packages("RODBC")
channel <- odbcConnectExcel("myfile.xls")
Importing data from SPSS
install.packages("Hmisc")
mydataframe <- spss.get("mydata.sav", use.value.labels=TRUE)
Importing data from SAS
SAS program:
> proc export data=mydata
> outfile="mydata.csv"
> dbms=csv;
> run;

0 Comments