0

in R, Let's say I have strings like:

str0 <- NA
str1 <- c("aaa")
str2 <- NA
str3 <- c("bbb")
str4 <- NA

when I do:

paste(str0, str1, str2, str3, str4, sep=',')

I got:

,aaa,,bbb,

But what I really need is:

aaa,bbb

So how can I ignore the comma at begin, at last and at the middle (more then 2 commas)? Thanks in advance!

Rui Barradas
  • 44,483
  • 8
  • 22
  • 48
Huan Lu
  • 15
  • 4
  • 1
  • @RonakShah Thank you, Ronak! I was stuck at this for a long time, I did not succeed with your method because str0-str4 in my program is another concatenated string, but I was using collapse, hence, in the end, it is not technically a "na.omitable" string, then I switched to sep=',' at last by which time I firstly use collapse=',', problem solved! thank you for inspiration! – Huan Lu Aug 11 '20 at 02:33

0 Answers0