Вот базовое решение R с cut()
и aggregate()
data.df$lat_group <- cut(data.df$lat, breaks = seq(-180, 180, 5))
aggregate(trait ~ lat_group, data = data.df, FUN = mean)
lat_group trait
1 (-5,0] 1.3354512
2 (5,10] 0.8354512
aggregate(data.df[, c('lat', 'trait')], by = data.df['lat_group'], FUN = mean)
#or
#aggregate(data.df[, c('lat', 'trait')], by = list(lat_group = data.df$lat_group), FUN = mean)
lat_group lat trait
1 (-5,0] -0.7712082 1.3354512
2 (5,10] 6.5745415 0.8354512
Данные (копирование и вставка из @Jon Spring)
data.df <- read.table(
header = T,
stringsAsFactors = F,
text = "lat trait
-0.830361 5
-0.795028 0.113935
-0.729722 0.113935
-0.729722 0.113935
8.021833 3
5.473333 0.113935
5.436333 0.113935
7.366667 0.113935")