Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

values

Cell values and geometry attributes


Description

Get the cell values of a SpatRaster or the attributes of a SpatVector

Usage

## S4 method for signature 'SpatRaster'
values(x, mat=TRUE, dataframe=FALSE, row=1, nrows=nrow(x), col=1, ncols=ncol(x))

## S4 method for signature 'SpatVector'
values(x)

Arguments

x

SpatRaster or SpatVector

mat

logical. If TRUE, values are returned as a matrix instead of as a vector, except when dataframe is TRUE

dataframe

logical. If TRUE, values are returned as a data.frame instead of as a vector (also if matrix is TRUE)

row

positive integer. Row number to start from, should be between 1 and nrow(x)

nrows

positive integer. How many rows?

col

positive integer. Column number to start from, should be between 1 and ncol(x)

ncols

positive integer. How many columns? Default is the number of columns left after the start column

Details

If x is a SpatRaster, and matrix=TRUE, a matrix is returned in which the values of each layer are represented by a column (with ncell(x) rows). The values per layer are in cell-order, that is, from top-left, to top-right and then down by row. Use as.matrix for an alternative matrix representation where the number of rows and columns matches that of x, if x has a single layer. If matrix=FALSE, the values are returned as a vector. In cell-order by layer.

Value

matrix or data.frame

See Also

Examples

f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
r
x <- values(r)
x[3650:3655, ]
r[3650:3655]


ff <- system.file("ex/lux.shp", package="terra")
v <- vect(ff)
y <- values(v)
head(y)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.