Re: [R] average and median values for each of the class

2014-04-28 Thread arun
Hi, I noticed that if ?mean" or ?median in fun1 is changed to other functions, for e.g. ?sum, it will show error message. ##Using shortened version that runs library(plyr) fun1 <- function(data, .group) {     f1 <- function(x) c(x, mean(x, na.rm = TRUE), sum(x, na.rm = TRUE))     res <- ddply(da

Re: [R] average and median values for each of the class

2014-04-27 Thread Berend Hasselman
On 27-04-2014, at 11:01, Berend Hasselman wrote: > > On 27-04-2014, at 02:37, Nico Met wrote: > >> Dear all, >> >> I have a matrix (dimension, 16 x 12) where 2nd column represents class >> (1,1,1,1,1,2,2,2, etc) information. I want to estimate average and median >> values for each of the c

Re: [R] average and median values for each of the class

2014-04-27 Thread arun
Hi, You could also try: library(plyr) fun1 <- function(data, .group) {     f1 <- function(x) c(x, mean(x, na.rm = TRUE), median(x, na.rm = TRUE))     res <- ddply(data, .group, sapply, FUN = f1)     vec1 <- as.vector(table(res[, .group]))     indx <- sort(c(cumsum(vec1) - 1, cumsum(vec1)))     Un

Re: [R] average and median values for each of the class

2014-04-27 Thread Berend Hasselman
On 27-04-2014, at 02:37, Nico Met wrote: > Dear all, > > > > I have a matrix (dimension, 16 x 12) where 2nd column represents class > (1,1,1,1,1,2,2,2, etc) information. I want to estimate average and median > values for each of the class and add this information as a row at end of > the ea

Re: [R] average and median values for each of the class

2014-04-26 Thread David Winsemius
On Apr 26, 2014, at 5:37 PM, Nico Met wrote: > Dear all, > > > > I have a matrix (dimension, 16 x 12) where 2nd column represents class > (1,1,1,1,1,2,2,2, etc) information. I want to estimate average and median > values for each of the class and add this information as a row at end of > the

Re: [R] average and median values for each of the class

2014-04-26 Thread arun
Hi, Your dput() suggests dat as data.frame. ##Using the results you got, res2 <- do.call(rbind,lapply(unique(dat$class),function(i) {x1 <-rbind(dat[dat$class==i,], avg[avg$class==i,], med[med$class==i,]); rownames(x1)[!grepl("ara",rownames(x1))] <- paste0(c("Avg", "Med"), i); x1})) A.K. O

[R] average and median values for each of the class

2014-04-26 Thread Nico Met
Dear all, I have a matrix (dimension, 16 x 12) where 2nd column represents class (1,1,1,1,1,2,2,2, etc) information. I want to estimate average and median values for each of the class and add this information as a row at end of the each classes. for example: dput(dat) structure(list(class