mean_angle | R Documentation |
Calculates the mean angle of a vector
mean_angle(a, angle = c("degree", "radians"))
a |
vector of angle values |
angle |
("degree", "radians") to define angle in degrees or radians |
The arithmetic mean is not correct for calculating the central tendency of angles. This function is intended to return the mean angle for slope or aspect, which could be used in a focal or zonal function.
A vector of mean angle
Jeffrey S. Evans <jeffrey_evans@tnc.org>
library(terra)
mean_angle(c(180, 10))
mean(c(180, 10))
mean_angle(c(90, 180, 70, 60))
mean(c(90, 180, 70, 60))
mean_angle(c(90, 180, 270, 360))
mean(c(90, 180, 270, 360))
elev <- rast(system.file("extdata/elev.tif", package="spatialEco"))
asp <- terrain(elev, v="aspect")
s <- buffer(spatSample(asp, 20, as.points=TRUE,
na.rm=TRUE, values=FALSE), 5000)
plot(asp)
plot(s, add=TRUE)
d <- extract(asp, s)
cat("Mean angles of aspect", "\n")
tapply(d[,2], d[,1], mean_angle)
cat("arithmetic means of aspect", "\n")
tapply(d[,2], d[,1], mean, na.rm=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.