Try this: f <- function(x) { sub <- subset(t, select = x) cbind(Mean = rowMeans(sub, na.rm = T), Sd = apply(sub, 1, sd, na.rm = T)) #return(sub) }
do.call(cbind, lapply(lapply(seq(1, ncol(t), by = ncol(t)/4), seq, l = 3), f)) On Wed, Jun 18, 2008 at 11:17 AM, Daren Tan <[EMAIL PROTECTED]> wrote: > > Below example has 4 sets of triplicates, without using for loop and > iteratively cbind the columns, what is the "R-approach" of generating a > matrix of 8 columns that are the averages and standard deviations ? The > average and standard deviation columns should be side by side i.e. A.mean > A.sd B.mean B.sd C.mean C.sd D.mean D.sd > > > t <- matrix(rnorm(120), ncol=12)> (colnames(t) <- paste(rep(LETTERS[1:4], > each=3), 1:3, sep=".")) [1] "A.1" "A.2" "A.3" "B.1" "B.2" "B.3" "C.1" "C.2" > "C.3" "D.1" "D.2" "D.3" > _________________________________________________________________ > [[elided Hotmail spam]] > > [[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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[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.