View source: R/wind_functions.R
ddff2uv | R Documentation |
Converts wind direction (dd
) and wind speed (ff
)
information into u
/v
wind components (zonal and
meridional wind component).
ddff2uv(dd, ff = NULL)
dd |
only necessary if |
ff |
|
Converts data from wind speed and direction into the zonal
and meridional wind components (u
/v
).
Different inputs are allowed:
if ff
is a matrix: requires to contains at least the
two columns "ff"
and "dd"
.
if ff
is a data.frame
or zoo
object:
requires to contains at least the
two variables "ff"
and "dd"
.
if ff
is numeric
: dd
has to be provided
in advance. ff
and dd
have to be of the same length
or one has to be of length 1
(will be recycled).
Returns a data.frame
or zoo
object (depending on input ff
)
containing the u
and v
components
of the data. In addition, rad
(mathematical representation
of wind direction in radiant) is returned.
Reto Stauffer
uv2ddff
## Generate dd and ff variable
set.seed(0)
ff <- floor(abs(rnorm(20))*10)
dd <- sample(seq(0,359),20)
df <- data.frame('ff'=ff,'dd'=dd)
## Using with vectors
print(head(ddff2uv('dd' = dd, 'ff' = ff)))
## Using with data.frame
print(head(ddff2uv(df)))
## Using with matrix
print(head(ddff2uv(as.matrix(df))))
## Use with zoo
library("zoo")
set.seed(100)
Sys.setenv("TZ" = "UTC")
data <- zoo(data.frame(dd = runif(20, 0, 360), ff = rnorm(20, .2, 2)^2),
as.POSIXct("2019-01-01 12:00") + 0:19 * 3600)
data <- round(data,2)
head(data)
class(data)
## Calculate dd/ff
uv <- ddff2uv(data)
head(uv)
class(uv)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.