2016-02-25 64 views
0

我試圖使用calendarPlot功能的OpenAir的包R.如果我加載附帶的軟件包MYDATA數據框和運行下面的代碼,它工作正常:的OpenAir:calendarPlot不讀數據幀

calendarPlot(mydata, pollutant = "co", year = 2003) 

MYDATA數據幀是這樣的:

'data.frame': 65533 obs. of 10 variables: 
$ date: POSIXt, format: "1998-01-01 00:00:00" "1998-01-01 01:00:00" "1998- 01-01 02:00:00" "1998-01-01 03:00:00" ... 
$ ws : num 0.6 2.16 2.76 2.16 2.4 3 3 3 3.36 3.96 ... 
$ wd : int 280 230 190 170 180 190 140 170 170 170 ... 
$ nox : int 285 NA NA 493 468 264 171 195 137 113 ... 
$ no2 : int 39 NA NA 52 78 42 38 51 42 39 ... 
$ o3 : int 1 NA 3 3 2 0 0 0 1 2 ... 
$ pm10: int 29 37 34 35 34 16 11 12 12 12 ... 
$ so2 : num 4.72 NA 6.83 7.66 8.07 ... 
$ co : num 3.37 NA 9.6 10.22 8.91 ... 
$ pm25: int NA NA NA NA NA NA NA NA NA NA ... 

我有自己的數據幀,R1_Temp_cut,看起來像這樣:

'data.frame': 722880 obs. of 3 variables: 
$ DateTime: POSIXct, format: "2013-10-01 00:01:00" "2013-10-01 00:02:00"  "2013-10-01 00:03:00" "2013-10-01 00:04:00" ... 
$ Air.Temp: num 17.5 17.4 17.4 17.7 17.7 17.7 17.7 17.6 17.6 17 ... 
$ AirTemp : num 17.5 17.4 17.4 17.7 17.7 17.7 17.7 17.6 17.6 17 ... 

當我在我的數據我收到以下錯誤運行相同的代碼:

> calendarPlot(R1_Temp_cut, pollutant = "AirTemp", year = 2014) 
Error in calendarPlot(R1_Temp_cut, pollutant = "AirTemp", year = 2014) : 
    No data to plot - check year chosen 
In addition: Warning message: 
In match(x, table, nomatch = 0L) : NAs introduced by coercion 

我注意到,在MYDATA日期格式是POSIXt和R1_Temp_cut是POSIXct。我改變了格式到POSIXct,它仍然工作正常。幫助文件說日期格式應該是POSIXct。

數據幀R1_Temp_cut摘要:

> summary(R1_Temp_cut) 
    DateTime      Air.Temp  AirTemp  
Min. :2013-10-01 00:01:00 Min. :-4.10 Min. : 0.00 
1st Qu.:2014-02-03 11:46:45 1st Qu.:14.40 1st Qu.:14.40 
Median :2014-06-09 05:15:30 Median :18.20 Median :18.20 
Mean :2014-06-09 07:11:51 Mean :18.57 Mean :18.57 
3rd Qu.:2014-10-13 01:41:15 3rd Qu.:22.00 3rd Qu.:22.00 
Max. :2015-02-15 23:59:00 Max. :99.00 Max. :99.00 

我如何能拿到劇本與R1_Temp_cut數據幀運行任何想法,將不勝感激。

謝謝, 克雷格。

+0

如果我們比較這兩個data.frames,'mydata'在'POSIXt'格式的日期,而你的日期是'POSIXct'格式。也許是問題的根源。 – 2016-02-25 23:39:29

+0

我在mydata中將日期格式更改爲POSIXct並且運行良好。 str(mydata) 'data.frame':\t 65533 obs。 10個變量: $ date:_POSIXct_,format:「1998-01-01 00:00:00」「1998-01-01 01:00:00」「1998-01-01 02:00:00」「 1998-01-01 03:00:00「... –

回答

0

原來的函數calendarPlot必須將'date'列標記爲日期以使其起作用。 我從「日期時間」到「日期」改變了我的列名,並將其完美地工作:

names(R1_Temp_cut)[1] <- "date" 
calendarPlot(R1_Temp_cut, pollutant = "Air.Temp", year =2014) 

Output from calendarPlot