changeDBNames {fishWiDNR}R Documentation

Change type of variable names in Wi Fish Management Data

Description

Change type of variable names in Wi Fish Management Data.

Usage

changeDBNames(df, from = c("RDNR", "R", "DNR"), to = c("R", "RDNR", "DNR"),
  check.names = FALSE, ...)

changeFMDBNames(df, from = c("RDNR", "R", "DNR"), to = c("R", "RDNR",
  "DNR"), check.names = FALSE, ...)

Arguments

df

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

from

A single string that indicates the variable name type that currently exists in df (and the user wants to convert “from”).

to

A single string that indicates the variable name type that the user wantes to convert the variable names in df “to”.

check.names

A single logical that indicates whether the resulting names should be checked to ensure that they are syntactically valid variable names (for R). If necessary they will be adjusted (by make.names) so that they are syntactically correct, and also to ensure that there are no duplicate variable names.

...

Not yet implemented.

Details

This function can change variable names in a data frame consisting of Wi Fish Management Data. The three formats allowed are as follows:

Value

A data.frame exactly as in df but with new names.

Author(s)

Derek H. Ogle, dogle@northland.edu

Examples

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

## test from RDNR to R (these are the defaults)
dfR <- changeFMDBNames(df)
data.frame(names(df),names(dfR))

## test from R back to RDNR
dfRDNR <- changeFMDBNames(dfR,from="R",to="RDNR")
data.frame(names(df),names(dfR),names(dfRDNR))
all(names(df)==names(dfRDNR))

## test from RDNR to DNR
dfDNR <- changeFMDBNames(df,from="RDNR",to="DNR")
data.frame(names(df),names(dfDNR))

## Check names (same as changing to RDNR)
dfRDNR1 <- changeFMDBNames(dfR,from="R",to="DNR",check.names=TRUE)
data.frame(names(dfR),names(dfRDNR),names(dfRDNR1))
all(names(dfRDNR)==names(dfRDNR1))

## test from partial list of RDNR names to R
df2 <- df[,-c(1,4,7,10,16,32:47)]
df2R <- changeFMDBNames(df2)
data.frame(names(df2),names(df2R))
## ... and back ...
df2RDNR <- changeFMDBNames(df2R,from="R",to="RDNR")
data.frame(names(df2),names(df2R),names(df2RDNR))
all(names(df2)==names(df2RDNR))

## test from variables not in VarLookup of RDNR names to R
## variables at the end
df3 <- df
df3$junk <- 7
df3$junk2 <- "Derek"
df3R <- changeFMDBNames(df3)
data.frame(names(df3),names(df3R))

## variables at the beginning
nc <- ncol(df3)
df4 <- df3[,c(nc-1,nc,1:(nc-2))]
df4R <- changeFMDBNames(df4)
data.frame(names(df4),names(df4R))

## variables in the middle and separated
df5 <- df3[,c(1:10,nc-1,11:20,nc,21:(nc-2))]
df5R <- changeFMDBNames(df5)
data.frame(names(df5),names(df5R))

## Read in datafile (use check.names to allow spaces in names) ... this is DNR type of data
df1 <- read.csv(ftmp,stringsAsFactors=FALSE,check.names=FALSE,na.strings="-")
df1 <- setFMDBClasses(df1,type="DNR")
str(df1)

## test from DNR to R
df1R <- changeFMDBNames(df1,from="DNR")
data.frame(names(df1),names(df1R))

## test from R back to DNR
df1DNR <- changeFMDBNames(df1R,from="R",to="DNR")
data.frame(names(df1),names(df1R),names(df1DNR))
all(names(df1)==names(df1DNR))

## End(Not run)

## Check error message
## Not run: 
dfbad <- changeFMDBNames(df2,from="R",to="R")

## End(Not run)


[Package fishWiDNR version 0.0.6 Index]