I have data, for example --
foo
bar, john
bloggs
smith
william
jones, doug
I want to turn these into a list, where elements are foo, bar, john, bloggs
etc. I have tried to use a flatmap from the purrr
package which gives me a useless mess of a dataframe. I have also tried using a list like so, which very helpfully gives me the list I started with.
var_list = list()
i = 1
for (variable in variables_list) {
split = strsplit(variable, ',')
for (s in split) {
var_list[[i]] = trimws(s)
i = i + 1
}
}
In Java, I could do something like this:
list.stream()
.flatMap(s -> Stream.of(s.split(",")))
.map(String::trim)
.collect(Collectors.toList());
And accomplish this all in one line. As a secondary thing, since R bills itself as a functional language, is it possible to flatmap the data directly in something of a one-liner like in Java?