Expanding table to all possible factors
1
0
Entering edit mode
Daniel Brewer ★ 1.9k
@daniel-brewer-1791
Last seen 10.2 years ago
Hello, I have a particular measurement that can take integer values between 0 and 5. I have multiple measurements for about 50 samples and I working on a simulation where a random measurement is taken for each sample. This gives me a 50x10000 table (if there were 10000 runs). For each run I use table() to give me the freq of each score. I would like to join the frequencies of each run together so I can find the average frequency for each score etc. The problem is that if there is none of that particular score then table() does no produce a value e.g. suppose there were no 0 measurements the you would get: 1 2 3 4 5 18 81 55 34 12 rather than 0 1 2 3 4 5 0 18 81 55 34 12 so a simple cbind() would not work. Does anyone know a way to either get table to fill in empty values or to do a ragged join or the like. Many thanks -- ************************************************************** Daniel Brewer, Ph.D. Institute of Cancer Research Email: daniel.brewer at icr.ac.uk ************************************************************** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the a...{{dropped:2}}
Cancer Cancer • 773 views
ADD COMMENT
0
Entering edit mode
alex lam RI ▴ 310
@alex-lam-ri-1491
Last seen 10.2 years ago
Hi Daniel, If you turn your integers into factors then R will make the correct table. > x<-c(1,1,2,3,3,4,4,4,5) > x<-factor(x,levels=0:5) > table(x) x 0 1 2 3 4 5 0 2 1 2 3 1 > Cheers, Alex Alex C. Lam PhD student Dept. of Genetics and Genomics Roslin Institute, Edinburgh EH25 9PS UK ________________________________ From: bioconductor-bounces@stat.math.ethz.ch on behalf of Daniel Brewer Sent: Tue 12/4/2007 12:20 PM To: bioconductor at stat.math.ethz.ch Subject: [BioC] Expanding table to all possible factors Hello, I have a particular measurement that can take integer values between 0 and 5. I have multiple measurements for about 50 samples and I working on a simulation where a random measurement is taken for each sample. This gives me a 50x10000 table (if there were 10000 runs). For each run I use table() to give me the freq of each score. I would like to join the frequencies of each run together so I can find the average frequency for each score etc. The problem is that if there is none of that particular score then table() does no produce a value e.g. suppose there were no 0 measurements the you would get: 1 2 3 4 5 18 81 55 34 12 rather than 0 1 2 3 4 5 0 18 81 55 34 12 so a simple cbind() would not work. Does anyone know a way to either get table to fill in empty values or to do a ragged join or the like. Many thanks -- ************************************************************** Daniel Brewer, Ph.D. Institute of Cancer Research Email: daniel.brewer at icr.ac.uk ************************************************************** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the a...{{dropped:10}}
ADD COMMENT

Login before adding your answer.

Traffic: 747 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6