I have a list in R which contains 7 dates, and I want to search for those dates in another dataframe and change the value of another column.
My list is ("2015-03-29" "2016-03-27" "2017-03-26" "2018-03-25" "2019-03-31" "2020-03-29" "2021-03-28")
The data frame is:
df
date time time_prog value1 value2
2015-01-01 0:00 1 4532 334
2015-01-01 0:10 1 4589 485
2015-01-01 0:20 1 4232 324
2015-01-01 0:30 1 4689 345
2015-01-01 0:40 1 4572 354
2015-01-01 0:50 1 4129 455
2015-01-01 1:00 2 3332 324
2015-01-01 1:10 2 3589 475
2015-01-01 1:30 2 5532 384
2015-01-01 1:40 2 6589 685
2015-01-01 1:50 2 4552 534
2015-01-01 2:00 3 4549 475
2015-01-01 2:10 3 4232 384
2015-01-01 2:20 3 4289 455
.
.
.
omitted 331363 rows
What I want is a new column called time_prog2 that changes the value of time_prog by substraining 1 to the value of that column but starting when the column hour is equal to 3:00 and ending at the end of that day.
I tried using a loop but it changes all the values from the data frame until the end and that is not what I want, I just want a column to be changed for all the hours starting in 3:00 and until the end of the day, for 7 certain dates which are in a list. I also tried a loop with 2 conditions (if ... && ...) but it is really long and i left the computer for one hour and it was still running so that can not be the solution. Any idea? Sorry for my English, it is not my native language. Thank you!
Aucun commentaire:
Enregistrer un commentaire