I'm using the rnoaa package for the first time. The data output is in a format I have not used before. How can I convert this to a nice dataframe that is ready to manipulate? below is the code and output
library("rnoaa")
ncdc(datasetid='GHCND', stationid = "GHCND:USC00182906", datatypeid='PRCP',
startdate = '2006-01-01', enddate = '2007-01-01', limit=400, token =
"API CODE")
$meta
$meta$totalCount
[1] 169
$meta$pageCount
[1] 400
$meta$offset
[1] 1
$data
date datatype station value fl_m fl_q fl_so fl_t
1 2006-07-14T00:00:00 PRCP GHCND:USC00182906 5 H 0700
2 2006-07-15T00:00:00 PRCP GHCND:USC00182906 0 H 0700
3 2006-07-16T00:00:00 PRCP GHCND:USC00182906 0 H 0700
4 2006-07-17T00:00:00 PRCP GHCND:USC00182906 0 H 0700
5 2006-07-18T00:00:00 PRCP GHCND:USC00182906 0 H 0700
6 2006-07-19T00:00:00 PRCP GHCND:USC00182906 109 H 0700
7 2006-07-20T00:00:00 PRCP GHCND:USC00182906 0 H 0700
8 2006-07-21T00:00:00 PRCP GHCND:USC00182906 3 H 0700
If you access the $data
portion of the results from the ncdc()
call, it's already a data.frame
. There is nothing further you need to do. You can save it as its own object as follows.
library("rnoaa")
dataset <- ncdc(datasetid='GHCND', stationid = "GHCND:USC00182906", datatypeid='PRCP',
startdate = '2006-01-01', enddate = '2007-01-01', limit=400, token =
"API CODE")
df <- dataset$data
To verify that it is indeed a data.frame
you can check with:
> class(df)
[1] "data.frame"