2014-01-07 47 views
0

我有一些數據看起來像我想繪製的以下內容。第一列是日期,第二列是總是遞增的數字。繪製具有缺失值的歷史數據

date  raw 
2013-12-10 13.41 
2013-12-11 14.82 
2013-12-12 16.72 
2013-12-13 19.08 
2013-12-14 NA 
2013-12-15 20.87 
2013-12-16 21.60 
2013-12-17 25.58 
2013-12-18 26.19 
2013-12-19 NA 
2013-12-20 NA 
2013-12-21 NA 
2013-12-22 35.52 

我有這個小[R腳本:

#!/usr/bin/env Rscript 

# Read the data. 
data <- read.table("solar_generation.data", header=TRUE, as.is=TRUE) 
newdata <- na.omit(data) 
dates <-strptime(as.character(newdata$date), "%y-%m-%d") 
plot(dates, newdata$raw, type="l") 

當我運行它,我得到了Error in plot.window(...) : need finite 'xlim' values錯誤。

我在做什麼錯?

加成後評論:dput(newdata)生產:

structure(list(date = c("2013-12-05", "2013-12-05", "2013-12-06", 
"2013-12-07", "2013-12-08", "2013-12-09", "2013-12-10", "2013-12-11", 
"2013-12-12", "2013-12-13", "2013-12-15", "2013-12-16", "2013-12-17", 
"2013-12-18", "2013-12-22", "2013-12-26", "2013-12-27", "2013-12-28", 
"2014-1-01", "2014-1-02", "2014-1-03", "2014-1-04", "2014-1-06" 
), raw = c(2.17, 4.48, 5.24, 8.33, 9.52, 10.23, 13.41, 14.82, 
16.72, 19.08, 20.87, 21.6, 25.58, 26.19, 35.52, 50.05, 50.84, 
55.12, 60.17, 63.86, 67.95, 68.4, 72.51)), .Names = c("date", 
"raw"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
12L, 13L, 14L, 15L, 19L, 23L, 24L, 25L, 29L, 30L, 31L, 32L, 33L 
), class = "data.frame", na.action = structure(c(11L, 16L, 17L, 
18L, 20L, 21L, 22L, 26L, 27L, 28L), .Names = c("11", "16", "17", 
"18", "20", "21", "22", "26", "27", "28"), class = "omit")) 
+0

這有幾個原因。你可以用'dput'給我們重複的數據嗎? – ECII

+0

@ECII:我可以但我引用的數據和腳本是我所有的。將數據放入一個名爲'solar_generation.data'的文件中並運行該腳本。公平地說,上述一些數據缺失,但它們都是相同的格式。用'dput'數據編輯的問題。 – Sardathrion

+0

我認爲你應該在'strptime'中使用''%Y-%M-%d''作爲格式參數。 –

回答

2

dates <-strptime(as.character(newdata$date), "%y-%m-%d") 

是錯誤的。它應顯示爲:

dates <-strptime(as.character(newdata$date), "%Y-%m-%d")