3

i have got about 150k rows and 1 col, some rows have more than 1 word so what i need to do is to get all the rows "concatenated" into 1 row and separated by a ; this is what i have got now:

Client 1 John S 2 Carl 3 Katy Smith 4 J P Morgan Stanley

what i need to see is:

Client John S;Carl;Katy Smith;J P Morgan Stanley

i have tried:

paste(Client, sep = '', collapse = ';') but it does not work.

help please?

Raul Gonzales
  • 866
  • 1
  • 15
  • 28
  • 3
    Is `Client` a `data.frame`? You need to pass in a vector to `paste` – Mike H. Feb 07 '18 at 14:27
  • 1
    paste(df[,1], sep = '', collapse = ';') – Wyldsoul Feb 07 '18 at 14:27
  • [This question](https://stackoverflow.com/questions/6698839/is-there-a-way-to-paste-together-the-elements-of-a-vector-in-r-without-using-a-l) is pretty similar to yours. – jazzurro Feb 07 '18 at 14:31
  • @jazzurro i have explained my reasons for posting this question as i am a novice in the field. – Raul Gonzales Feb 07 '18 at 14:53
  • 1
    @RaulGonzales I understand your situation. There are a tons of questions on SO. If you type with a few key words for your task you would be able to find an answer or a hint. Would you be able to do that from next time before you ask? If you really cannot find any relevant question, you can ask for a help. :) – jazzurro Feb 07 '18 at 14:57
  • @jazzurro thanks for that! i struggle to explain myself sometimes although i know exactly what i want – Raul Gonzales Feb 07 '18 at 14:59

1 Answers1

5
df <- data.frame(x=c("John S", "Carl", "Katy Smith", "J P Morgan Stanley")) 
paste(df$x, collapse = ";")

[1] "John S;Carl;Katy Smith;J P Morgan Stanley"
abichat
  • 2,317
  • 2
  • 21
  • 39