csvToUMF: Convert .CSV File to an unmarkedFrame

View source: R/utils.R

csvToUMFR Documentation

Convert .CSV File to an unmarkedFrame

Description

This function converts an appropriatedly formated comma-separated values file (.csv) to a format usable by unmarked's fitting functions (see Details).

Usage

csvToUMF(filename, long=FALSE, type, species, ...)

Arguments

filename

string describing filename of file to read in

long

FALSE if file is in long format or TRUE if file is in long format (see Details)

species

if data is in long format with multiple species, then this can specify a particular species to extract if there is a column named "species".

type

specific type of unmarkedFrame.

...

further arguments to be passed to the unmarkedFrame constructor.

Details

This function provides a quick way to take a .csv file with headers named as described below and provides the data required and returns of data in the format required by the model-fitting functions in unmarked. The .csv file can be in one of 2 formats: long or wide. See the first 2 lines of the examples for what these formats look like.

The .csv file is formatted as follows:

  • col 1 is site labels.

  • if data is in long format, col 2 is date of observation.

  • next J columns are the observations (y) - counts or 0/1's.

  • next is a series of columns for the site variables (one column per variable). The column header is the variable name.

  • next is a series of columns for the observation-level variables. These are in sets of J columns for each variable, e.g., var1-1 var1-2 var1-3 var2-1 var2-2 var2-3, etc. The column header of the first variable in each group must indicate the variable name.

Value

an unmarkedFrame object

Author(s)

Ian Fiske ianfiske@gmail.com

Examples

# examine a correctly formatted long .csv
head(read.csv(system.file("csv","frog2001pcru.csv", package="unmarked")))

# examine a correctly formatted wide .csv
head(read.csv(system.file("csv","widewt.csv", package="unmarked")))

# convert them!
dat1 <- csvToUMF(system.file("csv","frog2001pcru.csv", package="unmarked"),
                 long = TRUE, type = "unmarkedFrameOccu")
dat2 <- csvToUMF(system.file("csv","frog2001pfer.csv", package="unmarked"),
                 long = TRUE, type = "unmarkedFrameOccu")
dat3 <- csvToUMF(system.file("csv","widewt.csv", package="unmarked"),
                 long = FALSE, type = "unmarkedFrameOccu")

unmarked documentation built on Sept. 11, 2024, 8:28 p.m.