绘制缺少值的历史数据

时间:2014-01-07 08:56:37

标签: r

我有一些看起来像我想要绘制的数据。第一列是日期,第二列是一个总是递增的数字。

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

1 个答案:

答案 0 :(得分:2)

该行

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

错了。它应该是:

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