I have the following R data.frame
df <- data.table(
id = c(1, 2, 3),
x = c(1, NA, NA),
y = c(NA, 2, NA),
z = c(NA, NA, 3))
And, I'd like to shift all data up from the "y" and all next columns without changing values order. The number of columns is variable. The final data set should be the following:
df_result <- data.table(
id = c(1, 2, 3),
x = c(1, NA, NA),
y = c(2, NA, NA),
z = c(3, NA, NA))
Please, help if you can!
Thanks