我想将特定列的值向右移动,而NA保持在左侧.
df = data.frame(a = c("one", "two", "three", "four", "five"),
x = c("l", "m", NA, NA, "p"),
y = c(NA, "b", "c", NA, NA),
z = c("u", NA, "w", "x", "y"))
a x y z
1 one l <NA> u
2 two m b <NA>
3 three <NA> c w
4 four <NA> <NA> x
5 five p <NA> y
这是我想要的输出
a x y z
1 one <NA> l u
2 two <NA> m b
3 three <NA> c w
4 four <NA> <NA> x
5 five <NA> p y