Created
January 19, 2015 13:46
-
-
Save johnDorian/c98613ceedfd64894eac to your computer and use it in GitHub Desktop.
modify hour of a subset using lubridate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lubridate) | |
## A synthetic data set. | |
doc <- data.frame(date=ymd_hm("2014-01-01 14:00") + (1:360)* 24*3600) | |
# Find all the dates before a certain time period. | |
index <- doc$date < ymd("2014-06-01") | |
## use the hour function to extract the hour of each day e.g | |
hour(doc$date) | |
## Now using the index from above you can subtract an hour from each of the times | |
# using the index vector and reassiging the modified hour back to the time stamp. | |
hour(doc$date[index]) <- hour(doc$date[index]) - 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment