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

About pvanb

I am a tropical forest ecologist with a focus on spatial and temporal patterns and processes at population and ecosystem level. I am furthermore very interested in issues related to conservation and sustainable use of biodiversity and natural resources under current and future climates. I have worked in the Middle East (Syria and Lebanon) and South America (Brazil) and in Eastern Africa (Kenya).
This entry was posted in Data handling, R computing environment and tagged , . Bookmark the permalink.

One Response to 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