varname: find variable name in source data set

View source: R/varname.R

varnameR Documentation

find variable name in source data set

Description

detect variable/column names in source data set

Usage

varname(type, src, return.na = FALSE, possibilities = FALSE)

Arguments

type

character, one of "date", "time", "focal", "behaviour", "actor", "receiver", "duration", "obstime" (observation time), "partner", "obsnumber", "observer" or "IDs"

src

usually a data.frame

return.na

by default FALSE, which results in the function stopping (returning an error) if a column is not found. If TRUE function will return NA in such a case (without producing an error). See also Details

possibilities

logical. If TRUE returns the possible matches for the given type that are considered by the function

Details

the case of "duration" is special, such a column is not mandatory and therefore might not be found either because it does not exist or because its column name is not among the templates provided in the function. In case no duration column is found, it is returned as NA and a message is returned to inform the user about the possible ambiguity. If type="IDs" an attempt is made to figure out whether there is one of the two possibilities of combinations of ID columns, i.e. (1) a focal and a partner column or (2) a focal, actor and receiver column

Value

character of variable name in the source data

Examples

x <- datagen()
varname("date", x[[1]])
varname("focal", x[[1]])

## Not run: 
  varname("observer", x[[1]]) # error
  varname("observer", x[[1]], return.na=TRUE) # works and returns NA

## End(Not run)

# return possible matches
varname("observer", x[[1]], possibilities=TRUE)

gobbios/socialindices documentation built on Feb. 14, 2023, 3:56 p.m.