Reputation: 1
I have dataset which have five variables: year, month, day, propertycrimes and sunset. Sunset is equal to 1 for the hour of sunset and the hour after sunset. I want to Keep only the 25 days each year that are between March 9 and April 3, and I want to Create a variable, Post2007, equal to 1 if the year is 2007 or later and equal to zero if the year is before 2007.
year month day sunset propertycrimes
2003 1 1 0 90
2003 1 1 1 4
2004 1 1 0 56
2004 1 1 1 4
2005 1 1 0 96
2005 1 1 1 10
2006 1 1 0 82
2006 1 1 1 5
2007 1 1 0 65
2007 1 1 1 7
library(readr)
dailycrimedataDD <- read_csv("dailycrimedataDD.csv")
View(dailycrimedataDD)
Upvotes: 0
Views: 31
Reputation: 13
could be done using dplyr
short <- dailycrimedataDD %>%
filter((month == 3 & day >= 9 ) | (month == 4 & day <= 3)) %>%
mutate(Post2007 = if_else(year >= 2007,1,0))
Upvotes: 1