将表转换为行列矩阵

时间:2013-07-18 19:20:20

标签: r matrix

我有一个表格,我想将其转换为行和列的矩阵:

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

我正在关注this post,其中说在R中使用“library reshape”。

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

但我得到了加法结果:

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

我希望列名的每个实例都有各自的计数,因为它们属于不同的类别。

0 个答案:

没有答案