Re: [R] Grouping data

From: Andrew Robinson <A.Robinson_at_ms.unimelb.edu.au>
Date: Thu, 17 Jan 2008 07:13:57 +1100

Hi Kimmo,

try cut() to create a factor with levels according to the range of values, and (among other options) table() to make the table.

Cheers

Andrew.

On Wed, Jan 16, 2008 at 10:06:23PM +0200, K. Elo wrote:
> Hi,
>
> I am quite new to R (but like it very much!), so please apologize if
> this is a too simple question.
>
> I have a large data frame consisting of data from a survey. There is,
> for example, information about age and education (a numeric value from
> 1-9). Now I would like to extract the total amount of each type of
> education within different age groups (e.g. from 18 to 25, from 25 to
> 35 etc.). How could I achieve this? (I have been thinking about
> using 'subset', but if there are better ideas they are welcome :) )
>
> An example might clarify my point. Let's assume the following data:
> # age edu
> 1 25 2
> 2 33 5
> 3 22 3
> 4 19 1
> 5 21 3
> 6 30 4
> 7 32 4
> 8 31 1
>
> What I want to have is:
>
> edu 18-25 25-35 ...
> 1 1 1
> 2 1 0
> 3 2 0
> 4 0 2
> 5 0 1
>
> Thanks in advance & kind regards,
> Kimmo
>
> ______________________________________________
> 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.
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/

______________________________________________
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 16 Jan 2008 - 20:23:07 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 16 Jan 2008 - 21:30:07 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