setDBClasses {fishWiDNR}R Documentation

Set classes for variables in WiDNR Fish Management Data.

Description

Set classes for variables in WiDNR Fish Management Data.

Usage

setDBClasses(df, type = c("RDNR", "DNR", "R"), ...)

setFMDBClasses(df, type = c("RDNR", "DNR", "R"), ...)

Arguments

df

The data.frame that contains the Wi Fish Management Data (likely directly from the central database).

type

A single string that indicates the variable name type in df. The three choices – "RDNR", "DNR", and "R" – are described in full in changeDBNames.

...

Not yet implemented.

Details

This function is used to set the class type (e.g., integer, factor, etc.) for variables from the WiDNR Fish Management central database.

Value

A data.frame exactly as given in data except, possibly, with different classes for the variables.

Note

THIS IS EXPERIMENTAL AT THIS POINT (and not sure that it is really needed ... read.csv might do an adequate job of guessing variable class type).

Author(s)

Derek H. Ogle, dogle@northland.edu

Examples

data(VarLookup)

ftmp <- system.file("extdata", "FMDB_ex.csv",package="fishWiDNR")
## Read in datafile (note periods in names) ... this is RDNR type of data
df1 <- read.csv(ftmp,stringsAsFactors=FALSE,na.strings="-")
str(df1)

## Set classes (using default 'RDNR' type)
df1a <- setFMDBClasses(df1)
tmp <- cbind(sapply(df1,class),sapply(df1a,class),
             as.character(VarLookup$type[match(names(df1a),VarLookup$RDNR)]))
colnames(tmp) <- c("old","new","supposed to be")
tmp

## Set classes using R names (changed first using changeDBNames)
df1R <- changeDBNames(df1,from="RDNR","R")
df1Ra <- setFMDBClasses(df1R,type="R")
tmp <- cbind(sapply(df1R,class),sapply(df1Ra,class),
             as.character(VarLookup$type[match(names(df1Ra),VarLookup$R)]))
colnames(tmp) <- c("old","new","supposed to be")
tmp

## test from partial list of RDNR names
df2 <- df1[,-c(1,4,7,10,16,32:47)]
df2a <- setFMDBClasses(df2)
tmp <- cbind(sapply(df2,class),sapply(df2a,class),
             as.character(VarLookup$type[match(names(df2a),VarLookup[,"RDNR"])]))
colnames(tmp) <- c("old","new","supposed to be")
tmp


[Package fishWiDNR version 0.0.6 Index]