Hi there I have a dataframe of a whole lot of variables lets say, one of my variables is gender how do I simply get an average of all other variables by gender? -- View this message in context: http://n4.nabble.com/simple-data-manipulation-question-tp956600p956600.html Sent from the R help mailing list archive at Nabble.com.
for example:> d = data.frame(gender=c("m","f","unkown"), x=rnorm(300)) > tapply(d$x,d$gender,mean)f m unkown 0.0787628409 0.0940534765 -0.0005323276 regards, stefan On Wed, Dec 09, 2009 at 04:50:37PM -0800, dolar wrote:> > Hi there > > I have a dataframe of a whole lot of variables > > lets say, one of my variables is gender > how do I simply get an average of all other variables by gender? > -- > View this message in context: http://n4.nabble.com/simple-data-manipulation-question-tp956600p956600.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
Or like this: d = data.frame(gender=c("m","f","unkown"), x=rnorm(300)) ddply(d,"gender",summarise,mean=mean(x)) Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA --- On Thu, 12/10/09, smu <ml at z107.de> wrote:> From: smu <ml at z107.de> > Subject: Re: [R] simple data manipulation question > To: "dolar" <nyetlin at gmail.com> > Cc: r-help at r-project.org > Date: Thursday, December 10, 2009, 1:45 AM > for example: > > > d = data.frame(gender=c("m","f","unkown"), > x=rnorm(300)) > > tapply(d$x,d$gender,mean) > ? ? ? ? ???f? > ? ? ? ? ???m? ? > ? ? unkown > 0.0787628409? 0.0940534765 -0.0005323276 > > regards, > stefan > > > On Wed, Dec 09, 2009 at 04:50:37PM -0800, dolar wrote: > > > > Hi there > > > > I have a dataframe of a whole lot of variables > > > > lets say, one of my variables is gender > > how do I simply get an average of all other variables > by gender? > > -- > > View this message in context: http://n4.nabble.com/simple-data-manipulation-question-tp956600p956600.html > > Sent from the R help mailing list archive at > Nabble.com. > > > > ______________________________________________ > > 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. > > > > ______________________________________________ > 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. >
?aggregate -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of dolar > Sent: Wednesday, December 09, 2009 5:51 PM > To: r-help at r-project.org > Subject: [R] simple data manipulation question > > > Hi there > > I have a dataframe of a whole lot of variables > > lets say, one of my variables is gender > how do I simply get an average of all other variables by gender? > -- > View this message in context: http://n4.nabble.com/simple-data- > manipulation-question-tp956600p956600.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
... or perhaps simpler is ?ave Bert Gunter Genentech Nonclinical Biostatistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Greg Snow Sent: Thursday, December 10, 2009 9:48 AM To: dolar; r-help at r-project.org Subject: Re: [R] simple data manipulation question ?aggregate -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of dolar > Sent: Wednesday, December 09, 2009 5:51 PM > To: r-help at r-project.org > Subject: [R] simple data manipulation question > > > Hi there > > I have a dataframe of a whole lot of variables > > lets say, one of my variables is gender > how do I simply get an average of all other variables by gender? > -- > View this message in context: http://n4.nabble.com/simple-data- > manipulation-question-tp956600p956600.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.______________________________________________ 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.
Scratch my suggestion. You have a data frame of variables which is what aggregate() is for. Bert Gunter Genentech Nonclinical Biostatistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Greg Snow Sent: Thursday, December 10, 2009 9:48 AM To: dolar; r-help at r-project.org Subject: Re: [R] simple data manipulation question ?aggregate -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of dolar > Sent: Wednesday, December 09, 2009 5:51 PM > To: r-help at r-project.org > Subject: [R] simple data manipulation question > > > Hi there > > I have a dataframe of a whole lot of variables > > lets say, one of my variables is gender > how do I simply get an average of all other variables by gender? > -- > View this message in context: http://n4.nabble.com/simple-data- > manipulation-question-tp956600p956600.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.______________________________________________ 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.