Plotting historical data with missing values

I have some data that looked like the following that I want to plot. The first column is a date and the second an always incrementing number.

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

I have this small R script:

#!/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")

When I run it, I get a Error in plot.window(...) : need finite 'xlim' values error.

What am I doing wrong?

Addition after comment: dput(newdata) produces:

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

Upvotes: 0

Views: 126

Answers (1)

The line

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

is wrong. It should read:

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

Upvotes: 2

Related Questions