date - Adjusting just the year of some data in R -


i have dataframe 730 observations , 1 of columns date column, of dates supposed 2007 , realise few seem have been mistakenly entered 2006. there way can use r select 2005's , change them 2008 without affecting month , day?

it in date format in r , looks this.

2005-05-21 

edit:

this output asked for:

structure(c(13604, 13604, 13604, 13604, 13604, 13604, 13604,  13604, 13604, 13604, 13604, 13604, 13604, 13604, 13604, 13604,  13604, 13604, 13604, 13604, 13597, 13597, 13597, 13597, 13597,  13597, 13597, 13597, 13597, 13597, 13598, 13598, 13598, 13598,  13598, 13598, 13598, 13598, 13598, 13598, 13607, 13607, 13607,  13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607,  13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607,  13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607,  13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607, 13607,  13607, 13608, 13608, 13608, 13608, 13608, 13608, 13608, 13608,  13608, 13608, 13608, 13608, 13608, 13608, 13608, 13608, 13608,  13608, 13608, 13608, 13598, 13598, 13598, 13598, 13598, 13598,  13598, 13598, 13598, 13598, 13598, 13598, 13598, 13598, 13598,  13598, 13598, 13598, 13598, 13598, 13597, 13597, 13597, 13597,  13597, 13597, 13597, 13597, 13597, 13597, 13597, 13597, 13597,  13597, 13597, 13597, 13597, 13597, 13597, 13597, 13605, 13605,  13605, 13605, 13605, 13605, 13605, 13605, 13605, 13605, 13605,  13605, 13605, 13605, 13605, 13605, 13605, 13605, 13605, 13605,  13608, 13608, 13608, 13608, 13608, 13608, 13608, 13608, 13608,  13608, 13608, 13608, 13608, 13608, 13608, 13608, 13608, 13608,  13608, 13608, 13244, 13244, 13244, 13244, 13244, 13244, 13244,  13244, 13244, 13244, 13244, 13244, 13244, 13244, 13244, 13244,  13244, 13244, 13244, 13244, 13600, 13600, 13600, 13600, 13600,  13600, 13600, 13600, 13600, 13600, 13600, 13600, 13600, 13600,  13600, 13600, 13600, 13600, 13600, 13600, 13613, 13613, 13613,  13613, 13613, 13613, 13613, 13613, 13613, 13613, 13613, 13613,  13613, 13613, 13613, 13613, 13613, 13613, 13613, 13613, 13613,  13610, 13610, 13610, 13610, 13610, 13610, 13610, 13610, 13610,  13610, 13610, 13610, 13610, 13610, 13610, 13610, 13610, 13610,  13610, 13610, 13610, 13616, 13616, 13616, 13616, 13616, 13616,  13616, 13616, 13616, 13616, 13616, 13616, 13616, 13616, 13616,  13616, 13616, 13616, 13616, 13616, 13616, 13616, 13616, 13616,  13616, 13616, 13616, 13616, 13616, 13616, 13616, 13616, 13616,  13616, 13616, 13616, 13616, 13616, 13616, 13616, 13618, 13618,  13618, 13618, 13618, 13618, 13618, 13618, 13618, 13618, 13618,  13618, 13618, 13618, 13618, 13618, 13618, 13618, 13618, 13618,  13621, 13621, 13621, 13621, 13621, 13621, 13621, 13621, 13621,  13621, 13621, 13621, 13621, 13621, 13621, 13621, 13621, 13621,  13621, 13621, 13622, 13622, 13622, 13622, 13622, 13622, 13622,  13622, 13622, 13622, 13622, 13622, 13622, 13622, 13622, 13622,  13622, 13622, 13622, 13622, 13620, 13620, 13620, 13620, 13620,  13620, 13620, 13620, 13620, 13620, 13620, 13620, 13620, 13620,  13620, 13620, 13620, 13620, 13620, 13620, 13622, 13622, 13622,  13622, 13622, 13622, 13622, 13622, 13622, 13622, 13622, 13622,  13622, 13622, 13622, 13622, 13622, 13622, 13622, 13622, 13622,  13622, 13622, 13623, 13623, 13623, 13623, 13623, 13623, 13623,  13623, 13623, 13623, 13623, 13623, 13623, 13623, 13623, 13623,  13623, 13623, 13623, 13623, 13623, 14080, 14080, 14080, 14080,  14080, 14080, 14080, 14080, 14080, 14080, 14080, 14080, 14080,  14080, 14080, 14080, 14080, 14080, 14080, 14080, 14080, 14081,  14082, 14083, 14084, 14085, 14086, 14087, 14088, 14089, 14090,  14091, 14092, 14093, 14094, 14095, 14096, 14097, 14098, 14099,  14100, 14101, 14102, 14103), class = "date")sked 

if want keep date format can following lubridate

library(lubridate)  year(yourdf$date)[year(yourdf$date)==2005] <- 2008 

here's example....

df <- data.frame(date =sys.date() - 1:4, col2 = 1:4)  df         date col2 1 2016-04-20    1 2 2016-04-19    2 3 2016-04-18    3 4 2016-04-17    4  # in example i'll change year 2016 2008  year(df$date)[year(df$date)==2016] <- 2008  df         date col2 1 2008-04-20    1 2 2008-04-19    2 3 2008-04-18    3 4 2008-04-17    4 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -