【发布时间】:2020-10-20 09:33:33
【问题描述】:
我想为每个样本点添加行,其中包含每年间隔的从到时间步长。因此,在添加的行中,我只想更改“from”和“to”列的内容,并保留上面行中的所有其他信息。
我现在拥有的:
> 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
我需要什么:
> 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
这里是示例数据框:
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)
我是 R 新手,这是我在这里的第一个问题,所以如果问题表述不完美、缺少某些内容或我错过了一个类似的问题以及我的问题的解决方案,请原谅我。 感谢您的任何提示!
【问题讨论】: