R - replace values in data frame using lookup table

后端 未结 1 1919
走了就别回头了
走了就别回头了 2021-01-03 14:20

I was having some trouble lately trying to replace specific values in a data frame or matrix by using a lookup-table.

So this represents the original.data to be modi

相关标签:
1条回答
  • 2021-01-03 14:50

    you can try :

    # x the original.data (a matrix)
    # y the lookup.table
    x2 <- y[match(x, y[,1]),2]
    dim(x2) <- dim(x)
    table(x, x2)
         x2
    x       1   2   3   4   5 255
      1    13   0   0   0   0   0
      2     0  22   0   0   0   0
      3     0   0  29   0   0   0
      4     0   0   0   8   0   0
      5     0   0   0   0  11   0
      6     0   0   4   0   0   0
      7     0   4   0   0   0   0
      8     0   5   0   0   0   0
      255   0   0   0   0   0 100
    
    0 讨论(0)
提交回复
热议问题