2021年1月29日星期五

Reshape long to wide adding additional columns

I have a dataframe that looks like this:

ID   X   Y     1   A   A   1   B   A   2   C   A   3   A   K   3   A   A  

All of the solutions used for repeated measurements etc. that I could find so far rely on one indicator that varies across all observations but in my case I do not have that. I basically want to summarize all of the observations in row for every ID in the data set.

In the end it should look like this in wide format

ID   X1   Y1   X2   Y2       1    A    A    B    A   2    C    A    NA   NA #since there is only one observation for 2 the values for X2 and Y2 should be NA  3    A    K    A    A  

Any idea how to do this? I would prefer to use data.table if possible.

https://stackoverflow.com/questions/65963493/reshape-long-to-wide-adding-additional-columns January 30, 2021 at 08:35AM

没有评论:

发表评论