I have a dataframe similar to data (see example below). I would like to create a vector containing all the string characters of IIIF separated by a comma as in out.
data=data.frame(IIIT=c("a", "b", "c", "d", "e", "f", "g"), IIIF=c("aze,hyt,fre", NA, "ade", "ijh, deg","oij,erf", "eft,kij", "efg,kijj,lerod,kjhyg"))
> data
IIIT IIIF
1 a aze,hyt,fre
2 b <NA>
3 c ade
4 d ijh, deg
5 e oij,erf
6 f eft,kij
7 g efg,kijj,lerod,kjhyg
> out
[1] "aze" "hyt" "fre" NA "ade" "ijh" "deg" "oij" "erf" "eft" "kij" "efg" "kijj" "lerod" "kjhyg"
How can I do that ?
>Solution :
Base R has strsplit() which will create a list, with each element of the list being a character vector of each separate word found in the original vector. You can then combine the results using unlist():
> unlist(strsplit(data$IIIF, split = ","))
[1] "aze" "hyt" "fre" NA "ade" "ijh" " deg" "oij" "erf"
[10] "eft" "kij" "efg" "kijj" "lerod" "kjhyg"