subset.LPJmLData: Subset an LPJmLData object

View source: R/LPJmLData_subset.R

subset.LPJmLDataR Documentation

Subset an LPJmLData object

Description

Function to extract a subset of the full data in an LPJmLData object by applying selections along one or several of its dimensions.

Usage

## S3 method for class 'LPJmLData'
subset(x, ...)

Arguments

x

An LPJmLData object

...

One or several key-value combinations where keys represent the dimension names and values represent the requested elements along these dimensions. Subsets may either specify integer indices, e.g. cell = c(27411:27416), band = -c(14:16, 19:32), or character vectors if the dimension has a dimnames attribute, e.g. band = c("rainfed rice", "rainfed maize").\ Coordinate pairs of individual cells can be selected by providing a tibble in the form of coords = tibble(lon = ..., lat =...). Coordinate values in the tibble need to be supplied as character vectors. The argument can also be called coordinates. When coordinates are supplied as character vectors to subset either along the lon or lat dimension or to subset by coordinate pair, the function matches the grid cells closest to the supplied coordinate value.

Value

An LPJmLData object with dimensions resulting from the selection in subset. Meta data are updated as well.

Examples

## Not run: 

vegc <- read_io(filename = "./vegc.bin.json")

# Subset cells by index
subset(vegc, cell = seq(27410, 27415))
# [...]
# $data |>
#   dimnames() |>
#     .$cell  "27409" "27410" "27411" "27412" "27413" "27414"
#     .$time  "1901-12-31" "1902-12-31" "1903-12-31" "1904-12-31" ...
#     .$band  "1"
# [...]

# Subset time by character vector
subset(vegc, time = c("2001-12-31", "2002-12-31", "2003-12-31"))
# [...]
# $data |>
#   dimnames() |>
#     .$cell  "0" "1" "2" "3" ... "67419"
#     .$time  "2001-12-31" "2002-12-31" "2003-12-31"
#     .$band  "1"
# [...]

## End(Not run)


lpjmlkit documentation built on March 31, 2023, 9:35 p.m.