我在2007-01-01 00到2013-12-31 23年间经营am模式。不是所有的观察结果都那么长,它们开始得更晚和/或结束得更早。在这种情况下,我想填写-9999值。我有:
[1,] "2003 09 01 01" "0"
[2,] "2003 09 01 02" "0"
[3,] "2003 09 01 03" "0"
[4,] "2003 09 01 04" "0" [1,] "2003 09 01 04" "0"
[5,] "2003 09 01 05" "0" [2,] "2003 09 01 05" "0"
[6,] "2003 09 01 06" "0" [3,] "2003 09 01 06" "0" --这将导致
[1,] "2003 09 01 01" "-9999"
[2,] "2003 09 01 02" "-9999"
[3,] "2003 09 01 03" "-9999"
[4,] "2003 09 01 04" "0"
[5,] "2003 09 01 05" "0"
[6,] "2003 09 01 06" "0"我的“参考日期”列创建如下:
library(gtools)
library(xts)
library(hydroTSM)
hips <- hip(from="2007-01-01 01",to="2014-12-31 23")
long.date <- strptime(x=hips, format = "%Y-%m-%d %H")
long.date.col <- cbind(format.POSIXlt(x=long.date,format="%Y %m %d %H"))
head(long.date.col)我必须为“日期”指定一种特定的格式,所以这一列最终具有类字符。
现在我想以某种方式合并它,但是合并不起作用。
有什么建议吗?感谢你的帮助!向Jochen致以最良好的问候
发布于 2015-04-29 08:08:09
试试这个(short是您的第二个矩阵的名称):
res <- as.matrix(merge(long.date.col, short, all.x = T))
res[is.na(res)] <- "-9999"https://stackoverflow.com/questions/29937424
复制相似问题