我有以下数据框,并且想将除前两列之外的所有列向下移动。基本上,我想看到一个“滞后”的数据框。似乎有很多关于如何为单个列获取此信息(请参见此处),但没有选择大多数列。
My data =
d1 <- data.frame(month = c("jan", "feb", "mar", "apr", "may", "june"),
conv = c(1, 3, 6, 2, 3, 8),
month = c("jan", "feb", "mar", "apr", "may", "june"),
visit = c( 1, 2, 4, 8, 16, 32),
click = c(64, 62, 36, 5, 6, 3))
d1
Desired output =
d2 <- data.frame(month = c("jan", "feb", "mar", "apr", "may", "june"),
conv = c(1, 3, 6, 2, 3, 8),
month = c(NA, "jan", "feb", "mar", "apr", "may"),
visit = c( NA, 1, 2, 4, 8, 16),
click = c(NA, 64, 62, 36, 5, 6))
d2
帮助?!