[R] matrix of mean values

arun smartpink111 at yahoo.com
Wed Oct 23 14:58:10 CEST 2013


Hi Nico,

Try:
dat<-read.table("pollShed.txt", header = T, sep = "\t",dec=",") 
 as.vector(sapply(split(dat,dat$name1),nrow))
 #[1]  86  10  43   3  20   7  25  12  18   3   7  12  12  14   3  14  25 175  59
#[20]  49  16   3  16  14  25  14  19   3  18   7   4   3  45  14  16   3  12 238
#[39]  12   3  25   9  20  12  12  15  20   7 170  16  12  45  14  25   3  12  14
#[58] 397   1   3  10 542  14  14  12  24  12   3  14  20   3   4   3  40  #### list element 59 produce the error 
lst1 <- split(dat,dat$name1)

t.test(lst1[[59]][,2],dat[,2])
#Error in t.test.default(lst1[[59]][, 2], dat[, 2]) : 
#  not enough 'x' observations

 res <- sapply(lst1[sapply(lst1,nrow)>1],function(x) t.test(x[,2],dat[,2])$p.value)
 head(res)
#      -99999       108946       111364       140400       149067       206262 
#4.508590e-01 9.142790e-05 4.911925e-09 7.124666e-01 1.376976e-03 3.161232e-02 



A.K.









On Wednesday, October 23, 2013 8:27 AM, Nico Met <nicomet80 at gmail.com> wrote:

Many thanks Arun for the suggestion. 

However, I tried following and do not know why it shows error. Data attached.



 dat<-read.table("pollShed.txt", header = T, sep = "\t",dec=",") # works fine 

 mean1<-sapply(split(dat,dat$name1),function(x) t.test(x[,2],dat[,2])$statistic) 

# Error in t.test.default(x[, 2], dat[, 2]) : not enough 'x' observations


 pval<-sapply(split(dat,dat$name1),function(x) t.test(x[,2],dat[,2])$p.value)

# Error in t.test.default(x[, 2], dat[, 2]) : not enough 'x' observations

Thanks in advance



More information about the R-help mailing list