NCEP.array2df: Convert data from an array to a data frame

Description Usage Arguments Details Value Author(s) References Examples

View source: R/NCEP.array2df.R

Description

This function takes a 3-dimensional array of weather data, as returned by NCEP.gather, and converts it to a dataframe composed of latitude, longitude, datetime, and the weather data.

Usage

1
NCEP.array2df(wx.data, var.names=NULL)

Arguments

wx.data

either a single 3-D array of weather data, as returned by NCEP.gather, or a list of multiple 3-D arrays of different variables but with the exact same spatial and temporal dimensions and intervals.

var.names

an optional vector of names for the weather variables in the 3-D arrays to be used in the output data frame

Details

This is a function to convert the data contained in one or many arrays to a single data.frame.

The order of the names specified in var.names should correspond to the order of the list of input arrays in wx.data. Latitude, longitude, and datetime are named automatically and cannot be changed in the function call.

When converting the data from two or more 3-D arrays to a single data frame, all 3-D arrays must contain the exact same spatial and temporal dimensions and intervals.

Value

A data frame with the components of latitudes, longitude, datetime, and the weather variable(s) from the input data array(s).

Author(s)

Michael U. Kemp mukemp+RNCEP@gmail.com

References

Kemp, M. U., van Loon, E. E., Shamoun-Baranes, J., and Bouten, W. 2011. RNCEP:global weather and climate data at your fingertips. – Methods in Ecology and Evolution. DOI:10.1111/j.2041-210X.2011.00138.x.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Not run: 
library(RNCEP)
############################################################
############################################################
## In this first example, we take data from a single 3-D array
## and arrange them in a data.frame ##
#############################################################

## First query the temperature for a particular pressure level
## and datetime range ##
wx.extent <- NCEP.gather(variable='air', level=850,
    months.minmax=c(8,9), years.minmax=c(2006,2007),
    lat.southnorth=c(50,55), lon.westeast=c(0,5),
    reanalysis2 = FALSE, return.units = TRUE)
	
## Then convert the 3-D array to a data.frame ##
wx.df <- NCEP.array2df(wx.data=wx.extent, var.names='Temperature')

############################################################
############################################################
## In this second example, we take data from two 3-D arrays 
## and arrange them in a single data.frame ##
#############################################################

## Query the U (east/west) and V (north/south) wind components
## for a particular pressure level and datetime range ##
wx.uwnd <- NCEP.gather(variable='uwnd', level=850,
    months.minmax=c(8,9), years.minmax=c(2006,2007),
    lat.southnorth=c(50,55), lon.westeast=c(0,5),
    reanalysis2 = FALSE, return.units = TRUE)
wx.vwnd <- NCEP.gather(variable='vwnd', level=850,
    months.minmax=c(8,9), years.minmax=c(2006,2007),
    lat.southnorth=c(50,55), lon.westeast=c(0,5),
    reanalysis2 = FALSE, return.units = TRUE)	
	
## Then convert the two 3-D arrays to a single data.frame ##
wx.df <- NCEP.array2df(wx.data=list(wx.uwnd, wx.vwnd), 
    var.names=c('Uwind', 'Vwind'))

## End(Not run)

RNCEP documentation built on July 1, 2020, 7:10 p.m.