mean_angle {spatialEco}R Documentation

Mean Angle

Description

Calculates the mean angle of a vector

Usage

mean_angle(a, angle = c("degree", "radians"))

Arguments

a

vector of angle values

angle

("degree", "radians") to define angle in degrees or radians

Details

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.

Value

A vector of mean angle

Author(s)

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Examples

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) 


[Package spatialEco version 2.0-2 Index]