If I have a list like:
list <- list( "1" = data.frame(time=1:3, temp = sample(11:13)),
"3" = data.frame(time=1:3, temp = sample(11:13)))
list
$`1`
time temp
1 1 11
2 2 12
3 3 13
$`3`
time temp
1 1 11
2 2 12
3 3 13
Now I want to add a correction-value to columns temp, +1 for dataframe 1 and -1 for dataframe 3, so the result would be:
$`1`
time temp
1 1 12
2 2 13
3 3 14
$`3`
time temp
1 1 10
2 2 11
3 3 12
Let´s additionally assume I have multiple of those lists, where sometimes dataframe 3 or 1 may be missing, or even a dataframe 2 maybe included, which would need its own correction-factor... I tried strange things for dataframe 1:
list <- lapply(list, function(x) {x <- x$"1"$temp-1;x})
or
list <- lapply(list, function(x) {x <- x[x$temp+1,];x})
also tried to add a seq_along for the other dataframe in the list...nothing works, maybe because I don´t quite understand how the syntax works...