As Michael notes, scale is what you want. Also, your request has an incorrect definition of z scores:
d$y - mean(d$y)/sd(d$y) #incorrect (d$y - mean(d$y) ) / sd(d$y) #correct On Thu, Apr 16, 2009 at 7:40 AM, Michael Conklin <michael.conk...@markettools.com> wrote: > newDF<-as.data.frame(scale(oldDF)) > > see ?scale > > Hope that helps. > > Michael Conklin > > > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Karin Lagesen > Sent: Thursday, April 16, 2009 5:29 AM > To: r-help@r-project.org > Subject: Re: [R] performing function on data frame > > David Hajage <dhajag...@gmail.com> writes: > >> Hi Karin, >> >> I'm not sure I understand... Is this what you want ? >> >> d$y - mean(d$y)/sd(d$y) > > > > > Yes, and also a bit no. > > Each column in my data frame represents one data set. For every > element in this data set I want to know the z value for that > element. I.e: I want to create a new data frame from the old data > frame, where each element in the new data frame is > > newDF[i,j] = oldDF[i,j] - mean(d[,j]) / sddev(d[,j]) > > I could, I think, iterate like this over the data frame, but I keep > thinking that one of the apply functions should be employed... > > Karin > -- > Karin Lagesen, Ph.D. > karin.lage...@medisin.uio.no > http://folk.uio.no/karinlag > > ______________________________________________ > 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. > > ______________________________________________ > 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. > -- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~ ______________________________________________ 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.