compare row values over multiple rows (R)

巧了我就是萌 提交于 2019-11-30 16:34:18

Here is my code. I will post the explanation in some time.

require(plyr)
ddply(Data, .(ID), summarize, timeToEQ = Position(isTRUE, abs(diff(CC)) < 0.05 ))

  ID timeToEQ
1  1        3
2  2        2

EDIT. Here is how it works.

  1. ddply breaks Data into subsets based on ID.
  2. diff(CC) computes the difference between CC of successive rows.
  3. abs(diff(CC)) < 0.05) returns TRUE if the difference has stabilized.
  4. Position locates the first instance of an element which satisfies isTRUE.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!