[R] Subset results of tapply

Romain Francois rfrancois at mango-solutions.com
Thu Feb 7 13:20:27 CET 2008


Hi,

You can define your own function within tapply. Something like this 
should do the trick :

> tapply(tmp$pc, tmp$name, function(x) wilcox.test(x)$p.value )

Cheers,

Romain

-- 
Mango Solutions
data analysis that delivers

Introduction to R training course :: London :: 06-07 March 2008
http://www.mango-solutions.com/services/rtraining/r_intro.html



Dong-hyun Oh wrote:
> Dear UseRs,
>
> I would like to extract only p.value by performing wilcox.test with  
> tapply function.
>
> Example data.frame is as follows:
>  > tmp
>      name year      Dtt    Dt2t2      Dgt     Dgt2        ec         
> tc        pc
> 1    AUS 1991 1.162935 1.141352 1.168011 1.193882 1.0189098 0.9601735  
> 0.9783301
> 2    AUS 1992 1.141352 1.000000 1.193882 1.181406 1.1413519 0.8854061  
> 1.0105599
> 3    AUS 1993 1.000000 1.000000 1.181406 1.198598 1.0000000 0.9856568  
> 0.9856568
> 4    AUS 1994 1.000000 1.000000 1.198598 1.187553 1.0000000 1.0093005  
> 1.0093005
> 5    AUS 1995 1.000000 1.000000 1.187553 1.207423 1.0000000 0.9835433  
> 0.9835433
> .........................
> 15   AUT 1991 1.000000 1.000000 1.000000 1.023534 1.0000000 0.9770075  
> 0.9770075
> 16   AUT 1992 1.000000 1.000000 1.023534 1.000000 1.0000000 1.0235336  
> 1.0235336
> 17   AUT 1993 1.000000 1.000000 1.000000 1.012671 1.0000000 0.9874880  
> 0.9874880
> 18   AUT 1994 1.000000 1.000000 1.012671 1.010350 1.0000000 1.0022970  
> 1.0022970
> 19   AUT 1995 1.000000 1.000000 1.010350 1.029325 1.0000000 0.9815653  
> 0.9815653
> 20   AUT 1996 1.000000 1.000000 1.029325 1.053247 1.0000000 0.9772873  
> 0.9772873
> .......................
> .......................
>
> I execute the following command
>  > tapply(tmp$pc, tmp$name, wilcox.test)
>
> How can I extract only p.values of above command?
>
> Best,
>
> =========================================================
> Center of Excellence for Science and Innovation Studies,
> Royal Institute of Technology, Sweden
> e-mail: donghoh at infra.kth.se, doriaba2 at snu.ac.kr, oh.dongh at gmail.com
> cell phone: +46 73 563 45 22
>
> ______________________________________________
> 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.
>
>



More information about the R-help mailing list