Reshape data for values in one column

前端 未结 2 1326
别跟我提以往
别跟我提以往 2020-12-11 11:43

My data.frame looks like this

ID | test | test_result
1  |  B   |   10
2  |  A   |   9
3  |  A   |   11
4  |  C   |   7
5  |  F   |   5

And

2条回答
  •  自闭症患者
    2020-12-11 12:32

    dcast from the reshape2 package does this:

    require(reshape2)
    dcast(data, test ~ ID , value_var = 'test_result' )
    
    #  test  1  2  3  4  5
    #1    A NA  9 11 NA NA
    #2    B 10 NA NA NA NA
    #3    C NA NA NA  7 NA
    #4    F NA NA NA NA  5
    

提交回复
热议问题