cor(x,y,na.method="omit") will drop each row of x and y
that contains an NA in any column of x or y. Thus, if
you give a subset of columns of x and/or y to it you may
get different rows omitted. See help(cor) for details.
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
> -----Original Message-----
> From: s-news-owner@lists.biostat.wustl.edu
> [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of
> Data Analytics Corp.
> Sent: Thursday, May 07, 2009 8:16 AM
> To: s-news@lists.biostat.wustl.edu
> Subject: [S] question on cor function
>
> Hi,
>
> I'm confused about what the cor function is producing. I
> have two data
> frames: pat and att. Each has 417 rows with missing data.
> The first,
> pat, has 4 columns; att has 30. I want the correlations between each
> column of pat with each column of att. My results should be
> a 30 by 4
> matrix. I used at first
>
> t(cor(pat, att, na.method = "omit"))
>
> and got my 30X4 matrix. The first cell, which should be for the
> correlation between pat[, 1] and att[, 1] is -0.24399252 But
> then, just
> for a check, I did cor(pat[, 1], att[, 1], na.method =
> "omit") and got a
> different answer! I got 0.001174417. What's going on???
> According to
> the Help file, the answer for my first statement with the transpose
> should be "a matrix such that the [i,j] element is the covariance
> (correlation) of x[,i] and either y[,j] or x[,j]. " So the
> [1,1] answer
> should be the correlation between pat[, 1] and att[, 1] - but
> it's not.
> What am I missing?? Am I just not seeing the obvious?? I'm
> using S+8.0
> on a Vista machine.
>
> Thanks,
>
> Walt
>
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> dataanalytics@earthlink.net
> www.dataanalyticscorp.com
>
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
|