[R] Query about getting a table of binned values

Francisco J. Zagmutt gerifalte28 at hotmail.com
Tue Jun 20 23:41:59 CEST 2006

Dear Lalitha

Take a look at ?cut and ?table. Cut will create categories of your 
continuous "Age" variable and table will create a contingency table of the 
categorized values against "Type"  i.e.

#Creates practice data frame

#Creates table
tab=table(dat$Type, cut(dat$Age,seq(0,1,.02)))

You can use the labels argument within cut to get a more pretty output

I hope this helps


Dr. Francisco J. Zagmutt
College of Veterinary Medicine and Biomedical Sciences
Colorado State University

>From: lalitha viswanath <lalithaviswanath at yahoo.com>
>To: r-help at stat.math.ethz.ch
>Subject: [R] Query about getting a table of binned values
>Date: Tue, 20 Jun 2006 13:57:07 -0700 (PDT)
>I am working with a dataset of age and class of
>Type A
>Type B
>Type K
>I wish to get a table that reads as follows
>          0-0.02   0.02-0.04 0.04-0.06 ..... 0.78-0.8
>Type A    15       20           5             8
>Type B     8        6 ....
>Type K     1        0           7
>I would appreciate your input regarding the
>appropriate functions to use for this purpose
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! 

More information about the R-help mailing list