[R] Using "subset" in correlation analysis

Mark Lyman mark.lyman at gmail.com
Wed Mar 19 15:08:16 CET 2008


James J. Roper <jjroper <at> gmail.com> writes:

> 
> The correlation test function says that it can do a subset where one 
> specifies the subsete vector.  I cannot seem to get it to work.
> 
> For example, the command line is:
> 
> cor.test(adults$Alt, adults$Cab, alternative="greater", method="pearson")
> 
> So, let´s say my subset vector is "Sex".  How would I state the command 
> to get the test of that subset?
> 
> Thanks in advance.
> 
> Jim

The subset argument only applies to the formula method. It should be a boolean 
vector something like the following (assuming adults is a data frame):

cor.test(~ Alt + Cab, adults, Sex=="MALE", alternative="greater", 
method="pearson")



More information about the R-help mailing list