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)
Run the code above in your browser using DataLab