Takes a collection of columns as a list, a dataframe, or equal length vectors and merges them together. This is used when you want to combine 2 or more similar columns after a merge/join/rbind and the values don't overlap (if the values overlap, overlapped values will be lost). The collection can be various data types.

combinecols(..., na.string = NA, returntype = c("character", "factor",
  "integer", "numeric"))

Arguments

...

A vector of columns, a list of columns, or a data.frame that you want to collect into a single column.

na.string

A character vector of string(s) which are to be interpreted as NA values. Blank observations are also considered to be missing values in logical, integer, numeric, and complex fields.

returntype

The data type you want the combined column to be. Choose one of, 'character', 'factor', 'integer', 'numeric'.

Examples

df <- data.frame( performingPhysio = c("jill", "jack", '', '') , operatingPhysio = c(NA, NA, NA, "shankman") , stringsAsFactors = FALSE ) df$physios <- combinecols( df$performingPhysio , df$operatingPhysio , na.string = c('', NA) , returntype = 'character' ) df
#> performingPhysio operatingPhysio physios #> 1 jill <NA> jill #> 2 jack <NA> jack #> 3 <NA> <NA> #> 4 shankman shankman
asd <- data.frame( col1 = as.factor(c(1:5, rep("", 15))) , col2 = as.integer(c(rep("", 7), 8:13, rep("", 7))) , col3 = c(rep("", 15), 16:20) , stringsAsFactors = FALSE ) qwe <- lapply(asd, function(x) x) asd$newCol1 <- combinecols( asd$col1 , asd$col2 , asd$col3 , na.string = '' , returntype = 'integer' ) asd$newCol2 <- combinecols( qwe , na.string = '' , returntype = 'factor' ) asd
#> col1 col2 col3 newCol1 newCol2 #> 1 1 NA 1 1 #> 2 2 NA 2 2 #> 3 3 NA 3 3 #> 4 4 NA 4 4 #> 5 5 NA 5 5 #> 6 NA NA <NA> #> 7 NA NA <NA> #> 8 8 8 8 #> 9 9 9 9 #> 10 10 10 10 #> 11 11 11 11 #> 12 12 12 12 #> 13 13 13 13 #> 14 NA NA <NA> #> 15 NA NA <NA> #> 16 NA 16 16 16 #> 17 NA 17 17 17 #> 18 NA 18 18 18 #> 19 NA 19 19 19 #> 20 NA 20 20 20