indexOf {ncdfCF}R Documentation

Find indices in the dimension domain

Description

Given a vector of numerical, timestamp or categorical values x, find their indices in the values of dimension y. With method = "constant" this returns the index of the value lower than the supplied values in x. With method = "linear" the return value includes any fractional part.

If bounds are set on the numerical or time dimension, the indices are taken from those bounds. Returned indices may fall in between bounds if the latter are not contiguous, with the exception of the extreme values in x.

Usage

## S4 method for signature 'character,ncdfDimensionCharacter'
indexOf(x, y, method = "constant")

## S4 method for signature 'numeric,ncdfDimensionNumeric'
indexOf(x, y, method = "constant")

## S4 method for signature 'ANY,ncdfDimensionTime'
indexOf(x, y, method = "constant")

Arguments

x

Vector of numeric, timestamp or categorial values to find dimension indices for. The timestamps can be either character, POSIXct or Date vectors. The type of the vector has to correspond to the type of y.

y

An instance of ncdfDimensionNumeric, ncdfDimensionTime or ncdfDimensionCharacter.

method

Single value of "constant" or "linear".

Value

Numeric vector of the same length as x. If method = "constant", return the index value for each match. If method = "linear", return the index value with any fractional value. Values of x outside of the range of the values in y are returned as 0 and .Machine$integer.max, respectively.

Examples

fn <- system.file("extdata",
                  "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20240101-20241231_vncdfCF.nc",
                  package = "ncdfCF")
ds <- open_ncdf(fn)
lon <- ds[["lon"]]
indexOf(c(8.5, 8.9, 9.3, 9.7, 10.1), lon)
indexOf(c(8.5, 8.9, 9.3, 9.7, 10.1), lon, "linear")

time <- ds[["time"]]
indexOf(c("2024-03-01", "2024-03-02"), time)

[Package ncdfCF version 0.1.1 Index]