View source: R/inputProcessingUtilties.R
columnParse | R Documentation |
Parses column names from input occurrence
data.frame
for more seamless function
columnParse(occs, wDepth = FALSE)
occs |
A |
wDepth |
Logical; flags whether a depth column should also be sought. |
This is an internal function to return the putative indices for latitude and longitude or x and y coordinates of occurrences to allow for code that is more robust to very common user error
A list
of length 2 with indices of the x and y
columns, respectively, followed by a message with a plain
text report of which columns were interpreted as x and y.
library(terra)
# Create sample raster
r <- rast(ncol=10, nrow=10)
values(r) <- 1:100
# Create test occurrences
set.seed(0)
longitude <- sample(ext(r)[1]:ext(r)[2],
size = 10, replace = FALSE)
set.seed(0)
latitude <- sample(ext(r)[3]:ext(r)[4],
size = 10, replace = FALSE)
set.seed(0)
depth <- sample(0:35, size = 10, replace = TRUE)
occurrences <- as.data.frame(cbind(longitude,latitude,depth))
# Here's the function
result <- columnParse(occs = occurrences[,1:2],
wDepth = FALSE)
result <- columnParse(occs = occurrences,
wDepth = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.