# setwd("./R_data") # dir() # entering data data1 <- read.table("hs0.csv", header=T, sep=",") # displaying variable names of data1 names(data1) # displaying the first 6 observations of data1 head(data1) # saves as an R object save(data1,file="data1.rda") # checking to see if data1.rda has been created dir() # clear everything out of memory rm(list=ls()) # checking that everything is gone ls() # load the R data into memory load("data1.rda") # display the last 6 observations of data1 tail(data1) # reading in hs0_1.csv (no column names) temp <- read.table('hs0_1.csv', sep=",") # supplying names names(temp) <- c("gender","id","race","ses","schtyp","prgtype", "read","write","math","science","socst") # list observations 5 through 10 to check the data temp[5:10, ] # reading in data over the internet hsb2<-read.table("http://www.ats.ucla.edu/stat/R/notes/hsb2.csv", sep=',', header=T) hsb2[1:5,] # reading inline data a<-read.csv(stdin()) gender,id,race,ses,schtyp,prgtype,read,write,math,science,socst 0,70,4,1,1,general,57,52,41,47,57 1,121,4,2,1,vocati,68,59,53,63,61 0,86,4,3,1,general,44,33,54,58,31 0,141,4,3,1,vocati,63,44,47,53,56 # chekcing a using the dim function dim(a) # reading fixed format data fixed <- read.fwf("schdat_fix.txt", width = c(2, 2, 2, 1, 2, 2, 1)) names(fixed) <- c("id", "a1", "t1", "gender", "a2", "t2", "tgender") # load library foreign for reading foreign datasets  library(foreign) # read stata data file hstata <- read.dta(file="hsb2.dta") head(hstata) # read stata data file from a web server hstata1 <- read.dta(file="http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta") head(hstata1)