Using any cumulative custom function

Is it possible with dplyr or with other R package use any custom cumulative function (i.e. cumulative linear trend, ) for given longitudinal data frame, with next variables:
x - numerical or categorical variable
ID - object ID
t - tenure (1,2,....)
For instance I would like to have linear trend for x[1:2], x[1:3], x[1:4],....for each ID and tenure
in the flexible way (with some dplyr function)

I'm not sure I totally understand your scenario, but are you talking about something akin to window functions?

You might also look at the window functions and functionality provided by the tsibble package
https://tsibble.tidyverts.org/articles/window.html
GIF from Earo Wang's talk on tsibble at rstudio::conf(2019)
tsibble window functions

5 Likes

Many thanks! :slight_smile: Yes, I was thinking about "stretch_dbl"

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Hi. I can not see where I can close my question

Here's a GIF of how you do it (I selected and then de-selected so that you can do it yourself) :slightly_smiling_face:

selecting a solution on rstudio community

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.