[R] concatenating columns in data.frame
ccberry @end|ng |rom he@|th@uc@d@edu
Thu Jul 1 21:15:19 CEST 2021
> On Jul 1, 2021, at 11:24 AM, Bert Gunter <bgunter.4567 using gmail.com> wrote:
> Why not simply:
> ## reprex
> df = data.frame("A"=sample(letters, 10), "B"=sample(letters, 10),
> "C"=sample(letters,10), "D"=sample(letters, 10))
> use_columns = c("D", "B")
> ## one liner
> df$combo_col <- do.call(paste,c(df[,use_columns], sep = "_"))
> In case you are wondering, this works because by definition *a date
> frame **is** a list*, so the concatenation is list concatenation.
Because I erroneously thought that there is a "data.frame' method for `c` and that this would cause a problem.
But I was wrong, so your solution wins.
More information about the R-help