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.
casetrim(df, case = c("upper", "lower"), colclasses = c("asis", "character"))
df | a dataframe or list of dataframes with columns of any character type |
---|---|
case | the letter case you want the output to be: |
colclasses | do you want to return every column to it's original data type ( |
toupper
, tolower
, trimws
df <- data.frame( performingPhysio = c("JILL jones ", " jack BLACK", "", " RegiNald ChesterField ") , operatingPhysio = c("Who Dat ", "chuck FLEMMING ", NA, " shankman, razor shankman") , consent = rep(FALSE, times = 4) , duration_hrs = 5:8 , stringsAsFactors = FALSE ) casetrim(df)#> performingphysio operatingphysio consent duration_hrs #> 1 3 3 TRUE 1 #> 2 2 1 TRUE 2 #> 3 1 <NA> TRUE 3 #> 4 4 2 TRUE 4casetrim( df , case = 'lower' )#> performingphysio operatingphysio consent duration_hrs #> 1 3 3 TRUE 1 #> 2 2 1 TRUE 2 #> 3 1 <NA> TRUE 3 #> 4 4 2 TRUE 4casetrim( df , case = 'lower' , colclasses = 'character' )#> performingphysio operatingphysio consent duration_hrs #> 1 jill jones who dat false 5 #> 2 jack black chuck flemming false 6 #> 3 <NA> false 7 #> 4 reginald chesterfield shankman, razor shankman false 8