I have a dataframe consisting of unique entries along the rows, descriptive characteristics for each entry in the first 8 columns, and then week-to-week prices in the columns afterwards. I would like to create a new dataframe that shows the same structure with week-to-week differences in prices in the non-descriptive columns.
So for instance, the 9th column would now show (Week 2 price - Week 1 price) instead of the current Week 1 price. I am having trouble figuring out how to iterate and wondering if it is even necessary to iterate. I am trying to apply seq_len but am not very familiar with the function.
Thanks for your help.
EDIT: Below is example dataframe. The output I hope for is the second structure.
structure(list(s = structure(1:3, .Label = c("aa", "bb", "cc"
), class = "factor"), w1 = c(3, 4, 5), w2 = c(55, 2, 1), w3 = c(52,
9, 3)), .Names = c("s", "w1", "w2", "w3"), row.names = c(NA,
-3L), class = "data.frame")
structure(list(s = structure(1:3, .Label = c("aa", "bb", "cc"
), class = "factor"), w1d = c(NA, NA, NA), w2d = c(52, -2, -4
), w3d = c(-3, 7, 2)), .Names = c("s", "w1d", "w2d", "w3d"), row.names = c(NA,
-3L), class = "data.frame")