#use data set C0204DT.txt from the books disk (chapter 2 data)
d=read.table(file=file.choose(),header=TRUE)
attach(d)
d
#we can see that we have two dichotomous variables
#the data set has already coded these numerically so there is no need to recode
#we can simply use our cor command to get the correlation coefficient.
cor(HOMEOWN,CANDIDAT)
#this matches what the books answer is
#note that the R package "psych" has a function when data are organized in matrix format; you can download this with the install.packages("psych")
#to find the rank order correlation we will need to pull the next data set from the book CD
#use data set C0205DT.txt from the books disk
b=read.table(file=file.choose(),header=TRUE)
attach(b)
b
#we can see that we have two variables, X and Y that are both ranked 1-5
#the basic cor command in R has a spearman rank command which is as follows
cor(X,Y,method="spearman")
#this gives us the same result as the book