Suppose I have a data frame with three variables as below. How do I create a new variable that for each group takes the first observation of x
?
group year x
1 2000 3
1 2001 4
2 2000 1
2 2001 3
3 2000 5
3 2001 2
I want to to create something like this:
group year x y
1 2000 3 3
1 2001 4 3
2 2000 1 1
2 2001 3 1
3 2000 5 5
3 2001 2 5