I have a data.frame in R that looks like this:
df <- data.frame(date=c(1,2,1,2), id=c(11,11,22,22), x=c(1,2,3,4))
But I want to rearrange it with a two new columns (depending on which id
is considered) as
df2 <- data.frame(date=c(1,2),x1=c(1,2),x2=c(3,4))
How can do it? What is the general approach to such tasks?