[R] use logical in cor.test

pgseye prseye at gmail.com
Tue Mar 30 10:41:08 CEST 2010


Thanks for the replies.

In response to Erik:
What does
> Both[,1]
show you?

> Both[,1]
   [1] 3.36   NA   NA   NA   NA   NA   NA 3.92 3.50   NA   NA   NA   NA 3.76
3.19 3.83   NA 3.66..........

What does
> Both[,1] > 2.5
show you? 

> Both[,1]>2.5
   [1]  TRUE    NA    NA    NA    NA    NA    NA  TRUE  TRUE    NA    NA   
NA    NA  TRUE  TRUE........


I understand a logical variable is binary, but don't know how to select a
subset of the data (have tried the subset function, but can't seem to get it
to work)

Bill, when I run what you suggested, I get:

> tBoth <- Both 
> is.na(tBoth[tBoth > 2.5]) <- TRUE 
Error in is.na(tBoth[tBoth > 2.5]) <- TRUE : 
  NAs are not allowed in subscripted assignments
> R <- cor(tBoth, use = "complete.obs") 
> R[1,2]
[1] 0.7750889

Any idea with the error message?

Thanks again,

Paul
-- 
View this message in context: http://n4.nabble.com/use-logical-in-cor-test-tp1744701p1744896.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list