Re: [R] Query about getting a table of binned values

From: Francisco J. Zagmutt <>
Date: Wed 21 Jun 2006 - 07:41:59 EST

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 <>
>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
> mailing list
>PLEASE do read the posting guide!
> mailing list PLEASE do read the posting guide! Received on Wed Jun 21 07:46:57 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 21 Jun 2006 - 08:13:50 EST.

Mailing list information is available at Please read the posting guide before posting to the list.