0

Below is the dataframe

enter image description here

I want to create 6th column where all the values of the 5 columns are combined. If a column has NA or 0, it shouldn't be considered.

There should be a space between each variable combined.

zx8754
  • 52,746
  • 12
  • 114
  • 209

1 Answers1

0

We can use

 df1$X6 <- apply(df1, 1, FUN=function(x) paste(x[!is.na(x)], collapse=" "))
akrun
  • 874,273
  • 37
  • 540
  • 662