values | R Documentation |
Get the cell values of a SpatRaster or the attributes of a SpatVector.
By default all values returned are numeric. This is because a vector or matrix can only store one data type, and a SpatRaster may consist of multiple data types. However, with values(x, dataframe=TRUE)
and as.data.frame(x)
the values returned match the type of each layer, and can be numeric, logical, integer, or factor.
## S4 method for signature 'SpatRaster' values(x, mat=TRUE, dataframe=FALSE, row=1, nrows=nrow(x), col=1, ncols=ncol(x), na.rm=FALSE, ...) ## S4 method for signature 'SpatVector' values(x, ...)
x |
SpatRaster or SpatVector |
mat |
logical. If |
dataframe |
logical. If |
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 |
na.rm |
logical. Remove |
... |
additional arguments passed to |
If x
is a SpatRaster
, and mat=FALSE
, the values are returned as a vector. In cell-order by layer. If mat=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(x, wide=TRUE)
for an alternative matrix representation where the number of rows and columns matches that of x
.
matrix or data.frame
values<-
, focalValues
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.