[R] Query about using table

apjaworski at mmm.com apjaworski at mmm.com
Thu Oct 26 21:05:19 CEST 2006


Lalitha,

Try something like

with(data, table(cut(age, n), member_FLAG))

where data is a data frame with columns named age and member_FLAG and n is
the number of age categories (bins) you want.  This will give you the
number of Ys and Ns in each bin, that you will need to convert to
percentages.

Also, you might want to check the help pages for table and cut.

Cheers,

Andy

__________________________________
Andy Jaworski
518-1-01
Process Laboratory
3M Corporate Research Laboratory
-----
E-mail: apjaworski at mmm.com
Tel:  (651) 733-6092
Fax:  (651) 736-3122


                                                                           
             lalitha viswanath                                             
             <lalithaviswanath                                             
             @yahoo.com>                                                To 
             Sent by:                  r-help at stat.math.ethz.ch            
             r-help-bounces at st                                          cc 
             at.math.ethz.ch                                               
                                                                   Subject 
                                       [R] Query about using table         
             10/26/2006 01:44                                              
             PM                                                            
                                                                           
                                                                           
                                                                           
                                                                           




Hi
I have data of the following form
ID  age  member_FLAG
1    25      Y
2    36.75   N
3    75.5    N
.........
.........

I want to get a histogram of this data showing
distribution of member_flag in each age-bin i.e. how
many values in each age bin have a member_flag of 'Y'
and how many have 'N'.
I was able to do the same using barplot2.

However I also need similar information in a tabular
form using percentages.
i.e in each age bin, what is the PERCENTAGE of IDs
with a member_flag of 'Y'

I am trying to work with table for the same, but would
appreciate some guidance regarding the above.

Thanks
Lalitha

______________________________________________
R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list