0

I need to plot a time series of temperature vs dates in R. However, each date have 24 datapoints as the temperature is measured each hour. I guess i need to make each datapoint unique in some way, but I can`t get this to work.

My data looks like this:

    dato     time      ampm  temp
 07.09.2012 12:20:17    AM  16.237
 07.09.2012 01:20:17    AM  16.237
 07.09.2012 02:20:17    AM  16.237
 .....
 07.25.2012 12:20:17    AM  16.332
 07.25.2012 01:20:17    AM  16.332
 07.25.2012 02:20:17    AM  16.332
 07.25.2012 03:20:17    AM  16.332

Any help would be greatly appriciated!

4

1 回答 1

1

下面我们使用 zoo 包。请注意,我们曾经text=Lines将示例保持为独立的,但实际上我们会用类似file="myfile.dat".

Lines <- "dato     time      ampm  temp
 07.09.2012 12:20:17    AM  16.237
 07.09.2012 01:20:17    AM  16.237
 07.09.2012 02:20:17    AM  16.237
 07.25.2012 12:20:17    AM  16.332
 07.25.2012 01:20:17    AM  16.332
 07.25.2012 02:20:17    AM  16.332
 07.25.2012 03:20:17    AM  16.332
"

library(zoo)
z <- read.zoo(text = Lines, header = TRUE, 
       index = 1:3, tz = "", format = "%m.%d.%Y %I:%M:%S %p")
plot(z)

在此处输入图像描述

于 2013-10-04T14:20:30.547 回答