compare row values over multiple rows (R)

前端 未结 1 1274
南旧
南旧 2021-01-03 15:22

I don\'t think this question has asked yet (most similar questions are about extracting data or returning a count). I am new to R, so any help would be appreciated!

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

    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.
    0 讨论(0)
提交回复
热议问题