Description Usage Arguments Examples
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.
1 2 | combinecols(..., na.string = NA, returntype = c("character", "factor",
"integer", "numeric"))
|
... |
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 |
returntype |
The data type you want the combined column to be. Choose one of, |
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 30 31 32 33 34 35 | 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
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.