Combining columns in dataframe

I am trying to combine the first five columns of my data frame into one column and can't get it to work. This is the code I have set up for it and cannot figure out why it isn't working. When I run the code it runs without error, but it does not combine the columns. Any suggestions?

data.frame(fdecstats) %>%
unite(fdecstats, P1 , c(P1, P2, P3, P4, P5), sep = " ", remove = TRUE, na.rm = FALSE)

It looks fine to me though I do not think the fdecstats in the unite command in needed.

You could try

unite( P1 , c(P1, P2, P3, P4, P5), sep = " ", remove =  TRUE, na.rm = FALSE)

but I don't think it makes a difference.

Can you supply some sample data?

A very simple and very effective way to supply some data is to use the dput() command.


and then simply copy the output and paste it here. If you have a very large data set then a sample should be fine. To supply us with 100 rows of your data set do

dput(head(mydata , 100))

where mydata is the name of your dataframe or tibble

Hmm, for some reason when I pulled the fdecstats out and ran what you have it worked. Thank you!

Weird, I thought I had tried it both ways with some sample data. Anyway, good luck.

Oh, another way to do this, I think, is:

cols = c(c("P1", "P2", "P3", "P4", "P5"))
apply(fdecstats[ , cols], 1, paste, collapse = "_")