Re: [R] Trying to get the prior value of a record from a data.frame . . . data.frame

2024-11-30 Thread Bert Gunter
I assume that the responses that John already received to his recent post met his needs. However, when I read it, I had a slightly different interpretation. So feel free to ignore the rest of this post if you like, but here's my interpretation and a simple solution to it. An example to help explai

Re: [R] Trying to get the prior value of a record from a data.frame . . . data.frame

2024-11-29 Thread Rui Barradas
Às 01:25 de 29/11/2024, Sorkin, John escreveu: I need to write code that will give me the previous value of from a data.frame. I have written the following code using the shift function from data.table . It does not work. I hope someone can help me correct the code. ###

Re: [R] Trying to get the prior value of a record from a data.frame . . . data.frame

2024-11-28 Thread Kimmo Elo
Hi, is there a specific reason to use "shift"? I mean, you could easily achieve what you described by simple indexing: --- snjp --- for (i in 1:10) { cat("x[i,num]",x[i,"num"],"\n") # Get previous value of x[i,"num"] zoop<-x[i-1,"num"] # NB! Returns "integer(0)" for ro

[R] Trying to get the prior value of a record from a data.frame . . . data.frame

2024-11-28 Thread Sorkin, John
I need to write code that will give me the previous value of from a data.frame. I have written the following code using the shift function from data.table . It does not work. I hope someone can help me correct the code. ### # Try to understand shift # #