dfTidy: Tidy Up a Data Frame

Description Usage Arguments Details Value Examples

View source: R/dfTidy.R

Description

Tidy up a data frame with respect to missing values, internal quotes, and white space.

Usage

1
2
3
4
5
dfTidy(
  df,
  missNums = c(-9999, -999.9, -999, 999, 9999),
  missChars = c("NA", "NULL", ".")
)

Arguments

df

A data frame to be tidied.

missNums

A numeric vector of numbers representing missing values in df, default c(-9999, -999.9, -999, 999, 9999).

missChars

A character vector of strings representing missing values in df, default c("NA", "NULL", ".", " ", " ").

Details

Missing values in df are replaced with NA for numeric vectors and "" for character vectors. Internal quotes and leading and trailing white space in character vectors are removed. Attempt is made to convert any character vectors of numbers to numeric.

Value

A tidied version of the original data frame.

Examples

1
2
3
4
5
mydat <- data.frame(a=c(1, 2, -999, 4, 5),
 b=as.factor(c("cat ", " dog", "frog", ".", " ant")),
 c=c("1.2", "NULL", "3.4", "5.6", "7.8"),
 stringsAsFactors=FALSE)
dfTidy(mydat)

JVAdams/EchoNet2Fish documentation built on Feb. 15, 2021, 4:27 a.m.