Paste multiple columns together

# your starting data.. data <- data.frame(‘a’ = 1:3, ‘b’ = c(‘a’,’b’,’c’), ‘c’ = c(‘d’, ‘e’, ‘f’), ‘d’ = c(‘g’, ‘h’, ‘i’)) # columns to paste together cols <- c( ‘b’ , ‘c’ , ‘d’ ) # create a new column `x` with the three columns collapsed together data$x <- apply( data[ , cols ] …

Read more

Why use purrr::map instead of lapply?

If the only function you’re using from purrr is map(), then no, the advantages are not substantial. As Rich Pauloo points out, the main advantage of map() is the helpers which allow you to write compact code for common special cases: ~ . + 1 is equivalent to function(x) x + 1 (and \(x) x …

Read more