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
Francisco J. Zagmutt
2006-Jun-20 21:41 UTC
[R] Query about getting a table of binned values
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 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) > >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 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