Hi, Why is the result of below "apply" call rotated with respect to the input and how to remedy this? Thanks, Joh .ZScore <- function(input){ #cat(input,"\n") z <- (input - mean(input))/sd(input) return(z) } apply(data.frame(x1=c(1,2,3,4,5),x2=c(2,3,4,5,6),x3=c(3,4,5,6,7)),1,.ZScore)
Use aaply from the plyr package. Hadley On Thu, May 27, 2010 at 6:24 AM, Johannes Graumann <johannes_graumann at web.de> wrote:> Hi, > > Why is the result of below "apply" call rotated with respect to the input > and how to remedy this? > > Thanks, Joh > > .ZScore <- function(input){ > ?#cat(input,"\n") > ?z <- (input - mean(input))/sd(input) > ?return(z) > } > > apply(data.frame(x1=c(1,2,3,4,5),x2=c(2,3,4,5,6),x3=c(3,4,5,6,7)),1,.ZScore) > > ______________________________________________ > R-help at 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. >-- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
On May 27, 2010, at 7:24 AM, Johannes Graumann wrote:> Hi, > > Why is the result of below "apply" call rotated with respect to the > input > and how to remedy this?Because the processing you requested is with respect to rows and the construction of matrices is by default by columns. ?t> > Thanks, Joh > > .ZScore <- function(input){ > #cat(input,"\n") > z <- (input - mean(input))/sd(input) > return(z) > } > > apply(data.frame(x1=c(1,2,3,4,5),x2=c(2,3,4,5,6),x3=c(3,4,5,6,7)), > 1,.ZScore)David Winsemius, MD West Hartford, CT
David Winsemius wrote:> > On May 27, 2010, at 7:24 AM, Johannes Graumann wrote: > >> Hi, >> >> Why is the result of below "apply" call rotated with respect to the >> input >> and how to remedy this? > > Because the processing you requested is with respect to rows and the > construction of matrices is by default by columns. > > ?tThanks. t solved my problem without having to load another package. Joh