How do I remove these characters from my vector of strings

I need a solution to how I can clean my vector of strings which has characters and symbols, for example

 [1]c("hiv3=0", "comdiab=0", "ppl=0")
[2]c("fxet3=1", "hiv3=0", "ppl=0")
[3]c("fxet3=1", "escol4=0", "alcool=0", "tipores3=1")
[4]c("escol4=0", "alcool=0", "ppl=0", "tipores3=1")

The intended string will broduce

[1]"hiv3=0,comdiab=0, ppl=0"
[2]"fxet3=1, hiv3=0, ppl=0"
[3]"fxet3=1, escol4=0, alcool=0, tipores3=1"
[4]"escol4=0, alcool=0, ppl=0, tipores3=1"

Any solution is acceptable, though I have tried using the

gsub

function Regex solution would be very much acceptable also

Do you mean you want to paste together the elements of each vector? For example:

paste(c("hiv3=0", "comdiab=0", "ppl=0"), collapse=", ")

[1] "hiv3=0, comdiab=0, ppl=0"

I'm not sure what type of object your string vectors are stored in, but here's an example where they are in a list:

library(tidyverse)

x = list(c("hiv3=0", "comdiab=0", "ppl=0"),
         c("fxet3=1", "hiv3=0", "ppl=0"),
         c("fxet3=1", "escol4=0", "alcool=0", "tipores3=1"),
         c("escol4=0", "alcool=0", "ppl=0", "tipores3=1"))

map(x, paste, collapse=", ")  
[[1]]
[1] "hiv3=0, comdiab=0, ppl=0"

[[2]]
[1] "fxet3=1, hiv3=0, ppl=0"

[[3]]
[1] "fxet3=1, escol4=0, alcool=0, tipores3=1"

[[4]]
[1] "escol4=0, alcool=0, ppl=0, tipores3=1"

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.