Re: [R] 2 factor split and lapply

2013-12-23 Thread arun
Hi, No problem. If you have two columns and need the ratio, you could use ?transform  testframe$data1 <- c(2.24,6.5,4.34) dcast(transform(testframe,ratio=data/data1),factor2~factor1,value.var="ratio",mean) #  factor2    a b #1   1 1.491071   NaN #2   2 0.483871 0.6461538 A

Re: [R] 2 factor split and lapply

2013-12-23 Thread Bert Gunter
As I said, ?tapply gives you an answer (without using other packages) . Read it. -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Mon, Dec 23, 2013 at 6:2

Re: [R] 2 factor split and lapply

2013-12-23 Thread arun
HI, I think this will be more appropriate. dcast(testframe,factor2~factor1,value.var="data",mean)   factor2    a   b 1   1 3.34 NaN 2   2 2.10 4.2 A.K. On Monday, December 23, 2013 9:37 AM, arun wrote: Hi, You could try: library(reshape2) dcast(as.data.frame(as.table(by(testframe[,3],te

Re: [R] 2 factor split and lapply

2013-12-23 Thread arun
Hi, You could try: library(reshape2) dcast(as.data.frame(as.table(by(testframe[,3],testframe[,-3],mean))),factor2~factor1,value.var="Freq") #  factor2    a   b #1   1 3.34  NA #2   2 2.10 4.2 A.K. On Monday, December 23, 2013 9:24 AM, Onur Uncu wrote: Sure, here is a reproducible exam

Re: [R] 2 factor split and lapply

2013-12-23 Thread Onur Uncu
Sure, here is a reproducible example: testframe<-data.frame(factor1=c("a","b","a"),factor2=c(1,2,2),data=c(3.34,4.2,2.1)) splitframe<-split(testframe,list(factor1=testframe$factor1,factor2=testframe$factor2)) lapply(splitframe,function(x)mean(x[,"data"])) The above lapply returns $a.1 [1] 3.34

Re: [R] 2 factor split and lapply

2013-12-22 Thread Bert Gunter
I believe you missed ?tapply which does what you want I think (in the absence of a reproducible example one cannot be sure). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisd

[R] 2 factor split and lapply

2013-12-22 Thread Onur Uncu
R Users, I have a data frame which I split using 2 factors using the split function: split(datframe, list(f=factor1, f2=factor2)); I then used lapply to get some summary statistics grouped by factor1 and factor2. I now want to change the appearance of this output. I want to get a 2 dimensional