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

From: Francisco J. Zagmutt <gerifalte28_at_hotmail.com>
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
dat=data.frame(Type=sample(c("TypeA","TypeB","TypeC"),100,replace=T),Age=runif(100))

#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

Francisco

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

>From: lalitha viswanath <lalithaviswanath@yahoo.com>
>To: r-help@stat.math.ethz.ch
>Subject: [R] Query about getting a table of binned values
>Date: Tue, 20 Jun 2006 13:57:07 -0700 (PDT)
>
>Hi
>I am working with a dataset of age and class of
>proteins
>#Age
>0
>0.03333
>0.6777777
>
>#Class
>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
>
>regards
>Lalitha
>
>______________________________________________
>R-help@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



R-help@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 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.