Combining text from data frame in one text string in R

Earlier I wrote about the custom STRJOIN function in OpenOffice. A very handy function when you need to combine all values in a row or column (or combination of the two), separated by a delimiter.

In R this is (also) very easy using paste with the collapse parameter set. For example:

my.data <- data.frame(letters[1:10])
paste(my.data[,1], collapse = "|")

[1] "a|b|c|d|e|f|g|h|i|j"

See here for a example how this can be used.

About these ads

One thought on “Combining text from data frame in one text string in R

  1. Pingback: Concatenate in SQLite | Ecostudies

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s