spatial_mean: Spatial mean over grid points

View source: R/analysis.R

spatial_meanR Documentation

Spatial mean over grid points

Description

Spatial mean over grid points

Usage

spatial_mean(
  data,
  value,
  by = c("year", "month"),
  weight = "coslat",
  lat_col = "latitude"
)

Arguments

data

Long data frame with a latitude column and the by columns

value

Name of the column to average

by

Group columns, for example c("year", "month") or "year"

weight

"coslat" weights each point by cos(latitude), so that points near the poles count less. NULL gives a plain mean.

lat_col

Name of the latitude column

Value

Data frame with the by columns and value. A date column is added when by holds year and month.

Examples

grid <- expand.grid(latitude = c(10, 20), longitude = 70, year = 2000, month = 1:2)
grid$t2m <- c(20, 30, 21, 31)
spatial_mean(grid, "t2m")

varunayan documentation built on Oct. 30, 2026, 1:07 a.m.