merge - Enlarge time series and fill with -9999 R -


i run model 2007-01-01 00 2013-12-31 23. not observations long, start later and/or end earlier. in case want fill in -9999 values. i have:

[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"  

this shall result in

[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" 

my reference date column created following:

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) 

i have specify format "dates" column of class character eventually.

now want merge somehow, merge doesn't work.

any suggestions? thankful help! best regards jochen

try (short name of 2nd matrix):

res <- as.matrix(merge(long.date.col, short, all.x = t)) res[is.na(res)] <- "-9999" 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -