Using sample data, for example:
example=data.frame(x=c(1,2,3,4,5,6,7,8), y=c(1,2,3,4,5,6,7,8), z=c(1,2,3,4,5,6,7,8))
which is as follows:
xyz 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8
I would like to move all the values ββin the z column up two rows, while the rest of the data frame remains unchanged. The result should look like this:
xyz 1 1 1 3 2 2 2 4 3 3 3 5 4 4 4 6 5 5 5 7 6 6 6 8 7 7 7 NA 8 8 8 NA
I just found ways to move the column values ββdown or shift the entire data frame.
Any ideas? Thanks!
r dataframe
Anne
source share