I would like to add rows for each sample point containing the from-to time steps with annual intervals. So in the added rows I want to change only the content of the "from" and "to" columns and maintain all the other information from the row above.
What I have right now:
> sample_points
point from to label
1 2004-05-01 2007-05-01 cropland
2 2009-05-01 2012-05-01 grassland
3 2014-05-01 2016-05-01 forest
What I need:
> sample_points
point from to label
1 2004-05-01 2005-05-01 cropland
1 2005-05-01 2006-05-01 cropland
1 2006-05-01 2007-05-01 cropland
2 2009-05-01 2010-05-01 grassland
2 2010-05-01 2011-05-01 grassland
2 2011-05-01 2012-05-01 grassland
3 2014-05-01 2015-05-01 forest
3 2015-05-01 2016-05-01 forest
Here the example data frame:
point <- c("1", "2", "3")
from <- as.Date(c("2004-05-01", "2009-05-01", "2014-05-01"))
to <- as.Date(c("2007-05-01", "2012-05-01", "2016-05-01"))
label <- c("cropland", "grassland", "forest")
sample_points <- data.frame(point, from, to, label)
I am new to R and this is my first question here, so please forgive me if the question is not formulated perfectly, something is missing or I've missed a similar question with a solution for my problem. I'm thankful for any hints!