install.packages(“rmarkdown”)
# sets wd to the path on my computer;
setwd("C:\\Users\\hmon1\\Desktop\\10A Homework\\") #this is where you downloaded the HW1.csv file
# loads in data for the full population
pop<-read.csv("HW1.csv")
# sets the seed for the random number generator
set.seed(48183130) #use your student ID instead of 12345678
# assigns a "random" sample of 200 from the population to 'data'
data<-pop[sample(1:nrow(pop), 200, replace=FALSE),]
# produces a cross tabulation table.
crosstab <-table(data$Sex,data$Smokes)
crosstab
##
## No Yes
## Female 44 38
## Male 41 77
# get and round cell and marginal means;
round(prop.table(crosstab),2) #creates cell probabilities
##
## No Yes
## Female 0.22 0.19
## Male 0.20 0.38
round(prop.table(crosstab,1),2) #creates row probabilities
##
## No Yes
## Female 0.54 0.46
## Male 0.35 0.65
round(prop.table(crosstab,2),2) #creates column probabilities
##
## No Yes
## Female 0.52 0.33
## Male 0.48 0.67