in R: Two Way Match to Matrix

前端 未结 2 347
日久生厌
日久生厌 2021-01-24 22:42

If I have a data.frame

df <- data.frame(DEP=letters[1:5], ARR=letters[11:15], NO=1:5+5)

   DEP ARR  NO
1   a   k   6
2   b   l   7
3   c   m   8
4   d   n            


        
2条回答
  •  感情败类
    2021-01-24 23:03

    ?xtabs:

    xtabs(NO ~ ., data=df)
    #   ARR
    #DEP  k  l  m  n  o
    #  a  6  0  0  0  0
    #  b  0  7  0  0  0
    #  c  0  0  8  0  0
    #  d  0  0  0  9  0
    #  e  0  0  0  0 10
    

提交回复
热议问题