0

I have a table which I would like to convert into matrix of rows and columns:

x=read.table("file")
10716052        AF004884    2       AutonomicNervousDisorders
10716052        AF004884    11      CardiovascularDisorders
10716052        AF004884    9       GastrointestinalDisorders
10716052        AF004884    2       Hemorrhage
10716052        AF004884    1       MetabolicandNutritionalDisorders
10716052        AF004884    2       Musculo-skeletalSystem
10716052        AF004884    5       NervousSystem
10716052        AF004884    4       OphthalmicDisorders
10716052        AF004884    7       PathologicalDisorders
10716052        AF004884    5       PulmonaryDisorders
10716052        AF004884    2       RespiratorySystem
10716052        AF004884    3       SkinandAppendages
10716052        AJ251368    2       AutonomicNervousDisorders
10716052        AJ251368    11      CardiovascularDisorders
10716052        AJ251368    9       GastrointestinalDisorders
10716052        AJ251368    2       Hemorrhage
10716052        AJ251368    1       MetabolicandNutritionalDisorders

I am following this post which says to use "library reshape" in R.

library(reshape)
cast(x, V1 ~ V2)

But I am getting the additive results:

        V1 AF004884 AJ251368 AJ272268 L35901 M65212
1 10716052       12       12       12     12      1

I would like to have each instance of the column names with their respective counts as they belong to different categories.

Community
  • 1
  • 1
Rgeek
  • 419
  • 1
  • 9
  • 23
  • which column denotes category information? The last one? – Alex Jul 18 '13 at 19:39
  • Yes,The last column is category information. – Rgeek Jul 18 '13 at 20:22
  • I have tried this from ecodist package: > crosstab(a$V2,a$V3,a$V4): AF004884 AJ251368 AJ272268 L35901 M65212 10716052 53 53 53 42 2 But Its giving me additive results from column V4,I want them to be as it is as per the categories. – Rgeek Jul 18 '13 at 20:25
  • 1
    Can you try `cast(x, V3 ~ V1, value="V2")` Not sure if this is what you want. – Alex Jul 18 '13 at 20:29
  • Actually I need V3 ~ V2, value="V4") but it still gives me additive results. – Rgeek Jul 18 '13 at 20:38
  • This?: `cast(x, V4 ~ V1 + V2, value="V3")` The leftmost column is gonna be the categories. The column name will V1*V2. It's gonna look like this: http://img812.imageshack.us/img812/9674/t740.png – Alex Jul 18 '13 at 20:40

0 Answers0