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
  • 46,390
  • 10
  • 104
  • 180

1 Answers1

0

We can use

 df1$X6 <- apply(df1, 1, FUN=function(x) paste(x[!is.na(x)], collapse=" "))
akrun
  • 789,025
  • 32
  • 460
  • 575