我从2007-01-01 00到2013-12-31运行模型23.不是我的所有观察都是那么长,它们开始得晚和/或早点结束。在那种情况下,我想填写-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
答案 0 :(得分:1)
试试这个(short
是第二个矩阵的名称):
res <- as.matrix(merge(long.date.col, short, all.x = T))
res[is.na(res)] <- "-9999"