Currently I am looking for a way to use reshape() to make a long data frame with grouped data to a wide one. I only have the ID which groups the data from LR, but no variable which acts as a timevar inside the groups.
I'd like to use reshape() since it seems to be a simple function, but I still need a timevar to make it work. Is there a way to create one which gives the individual rows inside of the groups a number?
Or is there another approach?
The left one is how the data are right now and the right one is the kind of result I need.
In short, you need a timevar in order for these functions to work. In this case, I just created one by giving every LR with the same ID a unique number starting from 1 to the the max number of LR for that ID (that's the group_by and mutate functions). I then use pivot_wider (it's the latest tidyverse equivalent of reshape) to widen it into columns, generating NA where there are no values.
Beware that because we 'randomly' assign the timevar, the columns have no meaning themselves (e.g. the values in 1 could have been in 2 or 3, ... just by chance).
I don't know what you want to use this for, but I think this is what you wanted for now right?
EDIT: I have checked the columns and in my case the order of the values in the columns from left to right in the wide data frame is the same as from top to bottom in the groups of the long data frame. It worked out just as it was supposed to do.