Below is the dataframe
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.
Below is the dataframe
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.
We can use
df1$X6 <- apply(df1, 1, FUN=function(x) paste(x[!is.na(x)], collapse=" "))