Learn R Programming

SDMtune (version 1.1.0)

swd2csv: SWD to csv

Description

Save an '>SWD object as csv file.

Usage

swd2csv(swd, file_name)

Arguments

swd

'>SWD object.

file_name

character. The name of the file in which to save the object, see details.

Details

  • The file_name argument should include the extension (i.e. my_file.csv).

  • If file_name is a single name the function saves the presence absence/background locations in a single file, adding the column pa with 1s for presence and 0s for absence/background locations. If file_name is a vector with two names, it saves the object in two files: the first name is used for the presence locations and the second for the absence/background locations.

Examples

Run this code
# NOT RUN {
# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
                    pattern = "grd", full.names = TRUE)
predictors <- raster::stack(files)

# Prepare presence and background locations
p_coords <- virtualSp$presence
bg_coords <- virtualSp$background

# Create SWD object
data <- prepareSWD(species = "Virtual species", p = p_coords, a = bg_coords,
                   env = predictors, categorical = "biome")

# Save the SWD objct as a single csv file
swd2csv(data, "train_data.csv")

# Save the SWD objct in two separate csv files
swd2csv(data, c("presence.csv", "absemce.csv"))
# }

Run the code above in your browser using DataLab