[R] Filter Values Out of R Output

Chuck Cleland ccleland at optonline.net
Wed Sep 3 20:31:07 CEST 2008


On 9/3/2008 12:20 PM, Tobias Binz wrote:
> Hi list
> 
> Is there a possibility to filter certain values out of an R output?
> 
> In my case: I want to create a vector of p-values in a for loop that
> invokes for every increment cor.test() on two vectors.
> 
> I haven't found a way yet to tell cor.test() to only return the p-values
> instead of the whole text.

  str() will compactly display the structure of an object, including the
result of calling cor.test().  Once you know the structure, you can
isolate and save a component.

x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6,  3.1,  2.5,  5.0,  3.6,  4.0,  5.2,  2.8,  3.8)

str(cor.test(x, y, method = "kendall", alternative = "greater"))
List of 8
 $ statistic  : Named num 26
  ..- attr(*, "names")= chr "T"
 $ parameter  : NULL
 $ p.value    : num 0.0597
 $ estimate   : Named num 0.444
  ..- attr(*, "names")= chr "tau"
 $ null.value : Named num 0
  ..- attr(*, "names")= chr "tau"
 $ alternative: chr "greater"
 $ method     : chr "Kendall's rank correlation tau"
 $ data.name  : chr "x and y"
 - attr(*, "class")= chr "htest"

cor.test(x, y, method = "kendall", alternative = "greater")$p.value
[1] 0.05971947

> Thanks,
> Tobi
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list