2014-11-08 63 views

回答

2

這應該工作

# partial old data used for example 
timedata<- read.table(header = TRUE, sep =",", text = " 
timestamp, value 
01/01/2013 00:00:10,10 
01/01/2013 00:00:25,6 
01/01/2013 00:00:40,10 
01/01/2013 00:00:55,8 
") 
# for your old timestamp dataframe use: 
# colnames(olddata)<- c("timestamp", "value") to get a suitable header 

# create full sequence of timestamps 
filldata<-as.data.frame(format(seq(from=ISOdate(2013,1,1,hour=0),to=ISOdate(2013,1,1,hour=24), by="5 sec"), "%d/%m/%Y %H:%M:%S")) 
colnames(filldata)<- "timestamp" 

# merge and make NAs zero 
filleddata<- merge(filldata,timedata, by="timestamp", all=TRUE) 
filleddata$value[is.na(filleddata$value)]<- 0 
+0

感謝您的解決方案。 – Chandra 2014-11-09 01:02:35

相關問題