I do not understand how to create a new column "lagged" in data.frame. My current data is collected at the end of the data. One of the programs I need to send suggests that she collected the first one in the morning, so I need to mash column 2 into 1 row. The code I wrote just returns the same data.
How can I do it right?
Thanks.
D8 = structure(list(Date = structure(c(14396, 14397, 14398, 14399, 14400, 14403, 14404, 14405, 14406, 14407, 14410, 14411, 14412, 14413, 14414, 14417, 14418, 14419, 14420, 14421, 14424, 14425, 14426, 14427, 14428, 14431, 14432, 14433, 14434, 14435), class = "Date"), PL8 = c(0, 0, 0, 0, 76, 0, -334, -974, -104, 356, 378, -1102, -434, 266, -434, 444, 464, 0, 486, 406, -224, -214, 0, -4, 0, -188, 356, 322, -484, 436)), .Names = c("Date", "PL8"), row.names = c(NA, 30L), class = "data.frame") D8 D8[,3] = lag(D8[,2],k=-1) D8