Ram23
Ram23

Reputation: 91

How to combine the values in a column of dataframe

I have a dataframe with two column. I want to concatenate the values in a second column and return a string. How can I do this in R?

Upvotes: 0

Views: 85

Answers (1)

akrun
akrun

Reputation: 886938

You can use paste with the appropriate delimiter. Here, I am using ''. You can specify it to -, _ or anything else.

 paste(df$Col2, collapse="")

If there are NAs you could use na.omit

 paste(na.omit(df$V2), collapse="")

Upvotes: 1

Related Questions