View source: R/wind_functions.R
uv2ddff | R Documentation |
Takes u/v wind components (zonal and meridional wind components) as input and returns wind speed and meteorological wind direction.
uv2ddff(u, v = NULL, rad = FALSE)
u |
|
v |
|
rad |
|
Note: if both, u
and v
are provided they
do have to be of the same length OR one of them has to be of length 1.
The one with length 1 will be recycled.
Returns a data.frame
or zoo
object (depending on input
u
) with two columns named dd
and ff
containing wind speed (same physical unit as
input u
/v
) and wind direction. Wind direction
is either in meteorological degrees (0 from North, from 90 East,
180 from South, and 270 from West) or in mathematical radiant
if input rad = TRUE
.
Reto Stauffer
ddff2uv
## Generate data.frame with u/v components for all 4 main wind directions
data <- data.frame(name = c("N","E","S","W"),
u = c( 0, -1 , 0, 1 ),
v = c(-1, 0, 1, 0 ))
## Use data.frame input
ddff <- uv2ddff(data)
cbind(data, ddff)
## Use u/v components as two separate vector inputs
ddff <- uv2ddff(data$u, data$v)
cbind(data, ddff)
## Radiant
ddff <- uv2ddff(data, rad = TRUE)
cbind(data, ddff)
## Use with zoo
library("zoo")
set.seed(100)
Sys.setenv("TZ" = "UTC")
data <- zoo(data.frame(u = rnorm(20, 2, 5), v = rnorm(20, 0, 4)),
as.POSIXct("2019-01-01 12:00") + 0:19 * 3600)
head(data)
class(data)
## Calculate dd/ff
ddff <- uv2ddff(data)
head(ddff)
class(ddff)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.