I have a dataframe with a set of character strings in one column, and a grouping variable (a string, but could be a factor) in another. I'd like to collapse
the dataframe such that the strings are collapsed into elements by grouping-variable. For info, I'm then going to use Corpus(VectorSource(x))
on that vector (i.e., I'm collapsing to create documents).
So for example:
eg Type
1 tomato F
2 mushrooms F
3 snow W
4 chips F
5 rain W
This would be converted into a character vector with two elements, the members of 'W' and the members of 'F'. I know I can use:
a <- paste(x$eg,collapse=" ")
To get all of them and of course just manually create subsets (or loop).
I was wondering if there was a plyr
function (but couldn't see one), and I think tapply
or by
might be what I'm looking for (in base) but I'm not clear how they'd be used here.
I'm not looking to output a dataframe here, but exploring the flagged duplicates clearly those methods apply to this question.