Concatenate row-wise across specific columns of dataframe
Use unite
of tidyr
package:
require(tidyr)
data <- data %>% unite(id, F, E, D, C, sep = '_')
First parameter is the desired name, all next up to sep
- columns to concatenate.
Try
data$id <- paste(data$F, data$E, data$D, data$C, sep="_")
instead. The beauty of vectorized code is that you do not need row-by-row loops, or loop-equivalent *apply functions.
Edit Even better is
data <- within(data, id <- paste(F, E, D, C, sep=""))