casetrim: Standardize letter case and trim whitespace for dataframes

Description Usage Arguments See Also Examples

View source: R/casetrim.R

Description

Removes leading and trailing whitespace from every column in a dataframe or list of dataframes. At the same time it standardizes the case of the characters to either upper or lower case. This function works best with raw character data before converting data types and other data munging/feature engineering. Does handle a dataframe as it is, however, and returns every column in it's original data type as a dataframe.

Usage

1
2
casetrim(df, case = c("upper", "lower"), colclasses = c("asis",
  "character"))

Arguments

df

a dataframe or list of dataframes with columns of any character type

case

the letter case you want the output to be: upper or lower. Default is upper.

colclasses

do you want to return every column to it's original data type (asis) or simply return all cols as characters (character)? Default is asis.

See Also

toupper, tolower, trimws

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
df <- data.frame(
    performingPhysio = c(
      "JILL jones      "
    , "    jack BLACK"
    , ""
    , " RegiNald ChesterField "
    )
  , "operating Physio"  = c(
      "Who Dat      "
    , "chuck FLEMMING      "
    , NA
    , "          shankman
    , razor shankman"
    )
  , consent          = rep(FALSE, times = 4)
  , duration_hrs     = 5:8
  , stringsAsFactors = FALSE
  )

casetrim(df)
casetrim(
    df
  , case = 'lower'
)
casetrim(
    df
  , case       = 'lower'
  , colclasses = 'character'
)

Paul-James/pjames documentation built on Aug. 9, 2019, 12:18 p.m.