[英]R mean aspect calculation (circular statistics)
I have aspect data from DEM pixels forming individual areas. 我有来自形成单个区域的DEM像素的外观数据。 I would like to calculate the mean aspect for each polygon using this data.
我想使用此数据计算每个多边形的平均长宽比。 I wish to apply the function to every row of my df and store it in the 'Mean_Aspect' column.
我希望将该函数应用于df的每一行,并将其存储在“ Mean_Aspect”列中。
My dataframe looks like this: 我的数据框如下所示:
The code I have so far calculates the mean aspect if I copy an paste csv into it, but I cannot work out how to loop/apply to all. 到目前为止,如果我将粘贴的csv复制到其中,我到目前为止的代码会计算出平均方面,但是我无法弄清楚如何循环/应用于所有内容。 Values in 'angles' are example onkly.
“角度”中的值仅是示例。
data$Mean_Aspect <- 0
library(circular)
angles = c(200.072,204.037,198.591,193.151,192.779,187.503,198.549,196.675,199.618,191.083,187.242)
anglecir = circular(angles, type="angles", units="degrees",modulo="2pi", template='geographics')
mean(anglecir)
Any help/advice appreciated! 任何帮助/建议表示赞赏!
如果度数列包含要计算的角度 ,则可以尝试:
data$Mean_Aspect <- lapply(data$degrees, function(angles) mean(circular(angles, type="angles", units="degrees",modulo="2pi", template='geographics')))
We can use sapply
我们可以使用
sapply
data$Mean_Aspect <- sapply(data$Degrees, function(angles)
mean(circular(angles, type="angles", units="degrees",modulo="2pi",
template='geographics')))
data$Mean_Aspect
#[1] 129.184797 6.358874 243.757731 128.159000
data <- data.frame(FID = 0:3, Degrees = I(list(c(120.53, 133, 854),
c(338.629, 331.991, 323.4, 133.2, 432),
c(251.114, 248.003, 232.1), c(121.992, 134.326))),
Mean_Aspect = 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.