New matrix containing difference between row elements of original

后端 未结 3 1193
南笙
南笙 2020-12-22 09:53

I want to take an existing MxN matrix and create a new M-1xN matrix such that for each columns, the elements are the difference between adjacent row elements of the original

3条回答
  •  余生分开走
    2020-12-22 10:22

    It's very simple for numerical data (not sure why you have characters):

    diff(m)
    

    With the character data, this should work:

    diff(matrix(as.numeric(m), dim(m)))
    

提交回复
热议问题