From Greg.Snow at intermountainmail.org  Thu Jul  5 22:40:09 2007
From: Greg.Snow at intermountainmail.org (Greg Snow)
Date: Thu, 5 Jul 2007 14:40:09 -0600
Subject: [Rd] cor() and cor.test() (PR#9781)
In-Reply-To: <20070705194847.E007A1C957@slim.kubism.ku.dk>
Message-ID: <07E228A5BE53C24CAD490193A7381BBBAAD0F0@LP-EXCHVS07.CO.IHC.COM>

The cor function does not know how to look inside of data frames (unless
you give it the entire data frame as the only argument).  If Pollution
and Wet.days are columns of the data frame named Pollution (which I
infer from your problem statement below) then you can do things like:

> cor(Pollution$Pollution, Pollution$Wed.days)

Or

> cor( Pollution[ ,c('Pollution','Wet.days')] )

Or 

> with( Pollution, cor(Pollution, Wet.days) )

Or 

> attach(Pollution)
> cor(Pollution, Wet.days)
> detach()

The last one may have problems since the data frame has the same name as
the column.  The with option is prefered to the last one anyways.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-devel-bounces at r-project.org 
> [mailto:r-devel-bounces at r-project.org] On Behalf Of 
> kristle.krichbaum at gmail.com
> Sent: Thursday, July 05, 2007 1:49 PM
> To: r-devel at stat.math.ethz.ch
> Cc: R-bugs at biostat.ku.dk
> Subject: [Rd] cor() and cor.test() (PR#9781)
> 
> Hello,
> 
> I am trying to make a correlation matrix in R using cor() and 
> also to get the p-value for each correlation using 
> cor.test().  I can't get these commands to work. I'm getting 
> errors like the following:
> 
> cor(Pollution, Wet.days)
> Error in inherits(x, "data.frame") : Object "Wet.days" not 
> found cor("Pollution", "Wet.days") Error in cor("Pollution", 
> "Wet.days") : missing observations in cov/cor In addition: 
> Warning messages:
> 1: NAs introduced by coercion
> 2: NAs introduced by coercion
> 
> I know that "Wet.days" is there because when I type the name 
> of the data set
> (Pollution) it appears. There are no missing values in the 
> data set for there to be any NAs coerced. This is the example 
> given in Mick Crawley's book on R with Pollution data so it 
> should definitely work.
> 
> Can you help me to get it working, please?
> Kristle
> 
> --
> Kristle Krichbaum
> Graduate Assistant
> Hudson Lab
> 208 Mueller Lab
> University Park, PA 16801
> www.cidd.psu.edu
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] cor() and cor.test() (PR#9781)
Greg Snow