Concatenating Vector of Strings in R

sak

New Member
I have a vector (Label) of length 500 with first few elements as:
AAA
ABM
ACD

I want to create a new vector (NewLabel) such that it's elements are:

How do I do this?

Dason

paste is probably what you're looking for:
Code:
ex.data <- c("AAA", "ABM", "ACD", "ADR")
paste(ex.data, "_trades.dat", sep = "")

sak

New Member
paste is probably what you're looking for:
Code:
ex.data <- c("AAA", "ABM", "ACD", "ADR")
paste(ex.data, "_trades.dat", sep = "")
Sorry I should have mentioned this in my previous post. The Label vector (your c) is generated by reading from a file. So, I can't do the step:
ex.data <- c("AAA", "ABM", "ACD", "ADR")

So, I basically have a text file with 500 of these labels in them and I pull them in a vector.

Dason

So what's the problem? I was just creating example data to show you that it works. Whatever you call the vector just replace the label ex.data with the name of your vector.

sak

New Member
Sorry I am new to R and so my questions might be bit too naive.

Here is what I did to test my case:
Code:
c("a","b","c","d")
paste(c,"_data",sep="")
And I get the error:
Code:
Error in paste(c, "_data", sep = "") :
cannot coerce type 'builtin' to vector of type 'character'

Dason

c
paste(c("a", "b", "c", "d"), "_data", sep = "")