#################### ## Intro to R ## ## Lecture 1 ## ## Dave Armstrong ## ## ICPSR Sum Prog ## ## 6/23/2009 ## #################### # This document presents the page-by-page code to accompany the lecture notes for Lecture 1. ## Page 6 2+2 X <- 10 X <- 4+4 X ## Page 7 library(foreign) help(package='foreign') ## Page 8 spss.dat <- read.spss( "C:/documents and settings/dave/desktop/ICPSR_RIntro/r_example.sav", to.data.frame=T, use.value.labels=T) spss.dat ## Page 9 stata.dat <- read.dta("r_example.dta", convert.factors=T) ## Page 10 stata.dat$x2 attach(stata.dat) x2 detach(stata.dat) ## Page 11 x4 <- c(0,0,0,0,0,1,1,1,1,1) x4 stata.dat$x4 <- x4 ## Page 12 mean(stata.dat$x1) var(stata.dat$x1) summary(stata.dat) stata.dat$log_x1 <- log(stata.dat$x1) stata.dat ## Page 13 recode(stata.dat$x1, "c(1,2)=1; c(3,4,5,6)=2") stata.dat$recoded_x1 <- recode(stata.dat$x1, "c(1,2)=1; c(3,4,5,6)=2") stata.dat