[R] Convert dataframe to table with counts where column names become row names

ghinkle ghinkle at alnylam.com
Thu Aug 6 19:14:50 CEST 2009


Can anyone explain how best to go from a dataframe to a table (or better yet
a new dataframe) of counts, where the row names in the new table (or
dataframe) are the column names of the original df.

start w/
DF1 = 
           Pos1  Pos2 Pos3 ....
oligo1   G       C     A
oligo2   U       U     A
oligo3   G       C     C
oligo4   C       G     U
oligo5   A       A     G
.....

End with 

DF2 = 
           G  A  U C
Pos1   2   1 1 1
Pos2   1  1  1  2
Pos3  1  2  1  1
....

I know how to generate the counts of each one column at a time using
"table(DF1$Pos1)".
Is there a way to do this in one step?  Should I just write a for loop for
each of the columns?

thanks,

greg
-- 
View this message in context: http://www.nabble.com/Convert-dataframe-to-table-with-counts-where-column-names-become-row-names-tp24850797p24850797.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list