pdf("ex0104.pdf") # Read in data from ASCII formatted (Fixed With File) ex0104dat <- read.fwf("http://www.stat.ufl.edu/~winner/data/biostat/ex0104.dat", width=c(8), col.names=c("smksts")) # Create a categorical "factors" from smksts fsmksts <- factor(ex0104dat$smksts,levels=1:5) levels(fsmksts) = c("Never Smoked", "Quit>10 Years", "Quit<10 Years", "Current Cigarette", "Current Other") # Create a dataset (frame) from input data ex0104 <- data.frame(ex0104dat, fsmksts) # Attach the dataset for analysis attach(ex0104) # Give the frequencies for the categorical factor table(fsmksts) # Obtain the number of current smokers (have smksts scores > 3) ncurrent <- length(smksts [smksts > 3]) # Obtain the total number of observatons nall <- length(smksts) # Obtain the sample proportion of smokers propsmoke <- ncurrent/nall # Print the counts and proportion ncurrent nall propsmoke dev.off()