[R] Running wilcox.test function on two lists

Dimitrios Rizopoulos
Thu, 07 Sep 2006 20:11:39 -0000

try something like the following:

lis1 <- c(lapply(1:10, rnorm, n = 10))
lis2 <- c(lapply(1:10, rnorm, n = 10))
lis1[[5]] <- lis2[[8]] <- numeric(0)
############################################
ind <- sapply(lis1, length) > 0 & sapply(lis2, length) > 0
lis1 <- lis1[ind]
lis2 <- lis2[ind]

mapply(function(x, y) wilcox.test(x, y)$p.value, lis1, lis2)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
      http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting "Raj, Towfique" <trajnp at gmail.com>:

> Dear all,
> I'm a newbie to R and I would really apperciate any help with the
following:
>
> I have two lists, l1 and l2:
>
> l1:
> $"A*0101"
> [1] 0.076 0.109 0.155  0.077 0.09 0  0  0.073
> [9] 0.33  0.0034 0.0053
>
>
> $"A*0247"
> [1] 0 0 0.5 .004 0 0 0
>
> $"A*0248"
> [1] 0 0 0.3 0 0.06
>
> ....
>
> l2:
>
> $"A*1101"
> [1] 0.17  0.24  0.097  0.075  0.067
>
> $"A*0247"
> numeric(0)
>
> $"A*0248"
> [1] 0.031
>
> ....
>
> Basically, what I want to do is run wilcox.test() on each entry pair
> in the list.
>
> 1) I want to loop through the list to run wilcox.test for each entry
> of the list. How would I do that? mapply()?
>
>           wilcox.test(l0[[1]],l1[[1]]) for the first one and so on....
>
> 2) I want to exclude the list entry which has no values (i.e. A*0247).
>
> 3) Finally, I only want the to see the 'p-value' for each list
names.
> The output I want capture is only the 'p-value' object from
> wilcox.test.
>
>         name    p-value
>        A*0101  0.8329
>         ....       ....
>
> I'm grateful for any help, or any pointers to a good online tutorial.
>
> Thanks a lot in advance,
>
> -T.
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm