# The second file is in comma delimited format, so the "read.table" function (or variation) can be used # ?read.table # read.csv will convert the data trk06 <- read.csv("H06trk.csv") dim(trk06) trk06[1:10,] # All of the modifications for this file have been put in the file "trk.modify" # We can use the "source" function to read and execute the commands source("trk.modify.R") # summary of tracker data summary(trk06) # drop HHID and PN names(trk06) trk06 <- trk06[,-c(6,7)] summary(trk06) # Merge subset of "B" data with the tracker data # ?merge objects() model.data <- merge(H96B50.54,trk06) dim(model.data) names(model.data) # It looks like the merge went well now try some models # since we are done with cleaning and transforming data, we can use the "attach" function attach(model.data) # Use search() to see where data is located search() # model.data is now in the search path at #2 objects(2) # All of the variables are now objects at level 2. The "masked" message is because # we have a HHIDPN in our .GlobalEnv and also model.data. Remove the copy in .GlobalEnv remove(HHIDPN) # Since the data we are using is attached, there is no need to specify the frame name table(DEGREE,GENDER) table(GENDER,RACE) # Try a model lm(DPW ~ Age + Cigs) # To display additional information, use the summary function summary(lm(DPW ~ Age + Cigs)) # To write the output to a file, use the "sink" function sink(file="model1.output") summary(lm(DPW ~ Age + Cigs)) # To return to displaying output on the console, use "sink" with no options sink()