Reproducible data:
Start_Curr_Job <- c(2009, 2011, 2014)
End_Curr_Job <- c(2012, 2015, 2019)
data_clean <- data.frame(Start_Curr_Job, End_Curr_Job)
I have a data frame with columns "startyear" and "endyear". I am trying to create a 3rd column that will contain an inclusive list of all the years in between, but my code below is not working out.
For example, for startyear = 2009 and endyear = 2012, allyears should equal 2009, 2010, 2011, 2012.
Any suggestions will be appreciated. My code below:
data_clean <- data_raw %>%
filter(!is.na(Start_Curr_Job), !is.na(End_Curr_Job),
Start_Curr_Job != "NA", End_Curr_Job != "NA" ) %>%
mutate(Start_Curr_Job = as.numeric(Start_Curr_Job),
End_Curr_Job = as.numeric(End_Curr_Job)) %>%
mutate(all_years = seq(from = Start_Curr_Job, to = End_Curr_Job, by = 1))
Error Message: "Error in seq.default(from = Start_Curr_Job, to = End_Curr_Job, by = 1) : 'from' must be of length 1"
I also tried the following, but it produced allyears = "2019:2012", which is also not what I want.
for (row in 1:nrow(data_clean)) {
data_clean$years[row] <- list(data_clean$Start_Curr_Job[row]:data_clean$End_Curr_Job[row])
}