Thank you so much!
Why do do.call(rbind,lapply(lll,rbind)) and rbind(lapply(lll,rbind)) act so
differently? What is the tricky part of that?
do.call(rbind,lapply(lll,rbind))
statistic parameter p.value conf.int estimate null.value alternative
[1,] 2.775282 37.99977 0.008509272 Numeric,2 Numeric,2 0 two.sided
[2,] -1.498133 37.31294 0.1425116 Numeric,2 Numeric,2 0 two.sided
method data.name
[1,] Welch Two Sample t-test rnorm(20) and rnorm(20)
[2,] Welch Two Sample t-test rnorm(20) and rnorm(20)
rbind(lapply(lll,rbind))
[,1] [,2]
[1,] List,9 List,9
2014-08-26
发件人:PIKAL Petr petr.pi...@precheza.cz
发送时间:2014-08-26 17:58
主题:RE: RE: [R] How to do t.test to rows of a dataframe using apply family
function?
收件人:my1stboxmy1st...@163.com
抄送:R Helpr-help@r-project.org
Hi
Please reply also to rhelp, maybe others can offer better answer.
Well, are you aware that by unlist you get all results as character values and
not numbers?
Personally I would use lapply and do.call on final result to get it as data
frame.
Here is example
Some model list data
lll-vector(list,length=2)
lll
[[1]]
NULL
[[2]]
NULL
lll[[1]]-t.test(rnorm(20), rnorm(20))
lll[[2]]-t.test(rnorm(20), rnorm(20))
str(unlist(lll))
Named chr [1:22] 0.0091599930484716 37.9972278626102 ...
- attr(*, names)= chr [1:22] statistic.t parameter.df p.value
conf.int1 ...
do.call(rbind, lapply(lll, rbind))
statistic parameter p.value conf.int estimate null.value alternative
[1,] 0.009159993 37.99723 0.9927394 Numeric,2 Numeric,2 0 two.sided
[2,] 0.1256267 32.93057 0.9007913 Numeric,2 Numeric,2 0 two.sided
methoddata.name
[1,] Welch Two Sample t-test rnorm(20) and rnorm(20)
[2,] Welch Two Sample t-test rnorm(20) and rnorm(20)
Regards
Petr
From: my1stbox [mailto:my1st...@163.com]
Sent: Tuesday, August 26, 2014 10:44 AM
To: PIKAL Petr
Subject: Re: RE: [R] How to do t.test to rows of a dataframe using apply family
function?
Hi Petr,
Thank you! I use unlist() and rbind() because I want the result to be in the
form of a matrix.
Regards
Allen
2014-08-26
发件人:PIKAL Petr petr.pi...@precheza.cz
发送时间:2014-08-26 14:33
主题:RE: [R] How to do t.test to rows of a dataframe using apply family function?
收件人:my1stboxmy1st...@163.com,R Helpr-help@r-project.org
抄送:
Hi
If your function works for you why to bother with apply? If it does not give
you required results, please post some data and show us what is expected.
I would remove unlist from your function and declare list for storing data,
which seems to me more natural for storing results.
t.test.list=function(df,paired){
lll-vector(list, length=nrow(df))
for(i in 1:nrow(df)){
lll[[i]]=t.test(df[i,grp1],df[i,grp2],paired=paired)
}
names(lll)=rownames(df)
lll
}
Regards
Petr
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of my1stbox
Sent: Tuesday, August 26, 2014 3:26 AM
To: R Help
Subject: [R] How to do t.test to rows of a dataframe using apply family
function?
Hi All,
How to do t.test to rows (with two levels, or in other words, groups
of samples) of a dataframe using apply family function? I have done
that using function and loops. And my overall purpose is to calculate
DE genes from two groups of miRNA microarray samples. And I know limma
can do that, but it seems limma doesn't support paired t-test.
t.test.df=function(df,paired){
df.t=c()
for(i in 1:nrow(df)){
df.t=rbind(df.t,unlist(t.test(df[i,grp1],df[i,grp2],paired=paired)))
}
rownames(df.t)=rownames(df)
df.t
}
Bests!
Allen Chiu
2014-08-26
[[alternative HTML version deleted]]
__
R-help@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.
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či
zpožděním přenosu e-mailu.
V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout;
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je