Re: [R] splitting data frame based on a criteria

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Wed, 04 Jun 2008 11:34:02 +0200

Hi

the other possible option is to use split with suitable graphing technique or with lapply and appropriate function
e.g.

boxplot(split(X, Y>0))
histogram( ~ X|Y)

gives Marvin

r-help-bounces_at_r-project.org napsal dne 03.06.2008 21:11:29:

> ?by may be helpful here
> eg if dat is your data.frame and yf is a factor (created using ifelse)
> use by(dat,yf,mean) to compute the means for each level of yf
> hth, Ingmar
>
> On Jun 3, 2008, at 8:37 PM, Marvin Lists wrote:
>
> > Hi,
> > I have a data frame that I want to split into two based on the
> > values of a
> > variable in it.
> >
> > The variable Y has numeric values ranging between 0 through 70. I
> > want to
> > plot the frequencies of another variable X in two different cases:
> > - When Y = 0 and
> > - When Y > 0
> >
> > How does one go about doing this?
> >
> > In general, I want to do several analyses with this data frame that
> > are a
> > variation of the above situation, i.e. they require splitting the
> > data into
> > different age, gender etc. and then calculating separate means,
> > correlations
> > and so on for the different groups into which the data frame would
> > split.
> >
> > I am struggling with the correct syntax for achieving this.
> >
> > Reading through the documentation suggests that tapply and split
> > may be the
> > functions to use for my purposes but the examples in the
> > documentations
> > didn't help me understand how I could achieve this.
> >
> > I would appreciate any suggestions and help.
> >
> > Thanks,
> > Marvin
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.



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. Received on Wed 04 Jun 2008 - 10:26:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 04 Jun 2008 - 10:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive