I have a vector with a length of about 3000. I highlighted a specific point in the vector with which(...). Now I want to have -120 beforethis point and +120 afterthis point.
My list is as follows:
> testList$Date
[1] "01.01.2002" "02.01.2002" "03.01.2002" "04.01.2002" "07.01.2002"
[6] "08.01.2002" "09.01.2002" "10.01.2002" "11.01.2002" "14.01.2002"
[11] "15.01.2002" "16.01.2002" "17.01.2002" "18.01.2002" "21.01.2002"
[16] "22.01.2002" "23.01.2002" "24.01.2002" "25.01.2002" "28.01.2002"
[21] "29.01.2002" "30.01.2002" "31.01.2002" "01.02.2002" "04.02.2002"
[26] "05.02.2002" "06.02.2002" "07.02.2002" "08.02.2002" "11.02.2002"
[31] "12.02.2002" "13.02.2002" "14.02.2002" "15.02.2002" "18.02.2002"ect....
I could do for-loopto iterate over the list and save it as a sublist. However, I do not think it is very effective. How can I implement this in R?
I appreciate your answer!
UPDATE
When using, lapplyI get:
> 120BeforeSublist <- lapply(event, function(x) c(x-120, x))
> (120BeforeSublist)
[[1]]
[1] 1875 1995
However, I want to keep a sublist -120 before and +120 after.
source
share