library(terra)
x <- rast(nrow=10, ncol=10)
x[] <- round(10 * runif(100))
cell <- c(1, 20, 40, 80)
getValueByCell(x, cell = cell)
getValueByCell(x, cell = cell, format = 'matrix')
y <- setValueByCell(x, val = 20, cell = cell)
plot(y)
z <- setValueByCell(x, val = 30, cell = cell, format = 'matrix')
plot(c(x, y, z))
Run the code above in your browser using DataLab