how to convert a string to a vector of strings

306 Views Asked by At

I have a textfile with many partners who supports products at diefferent servicelevels.

Partner;Email;Telefon;Servicekarte;Unternummer;Fachhandel;Handel Partner1;[email protected];;9203;1;;product1,product2 Partner2;[email protected],[email protected];0621-12345678,0621-12345678;9225;1;product3;

I read this file with read_delim an put the result in a dataframe "partners". The result for partners[2, "Email"] is [email protected],[email protected].

Now i want to send a mail with blastula to all adresses in partners[2, "Email"]. Blastula needs a variable to = c("[email protected]", "[email protected]") for the recipients.

My question is how to get the variable to from partners[2, "Email"]

2

There are 2 best solutions below

0
Ric S On

You can use strsplit() to divide a text string on a particular character. It will return a list of length 1, so to obtain the desired result in a vector you just subset it

x <- "[email protected],[email protected]"
to <- strsplit(x, ",")[[1]]
to
# [1] "[email protected]"    "[email protected]"
0
KacZdr On

You can also use sub() for splitting your data:

x <- "[email protected],[email protected]"
part_two <- sub(".*,", "", x)
part_one <- sub(",.*", "", x)
to <- c(part_one,part_two)
to
# [1] "[email protected]"    "[email protected]"