I need to insert some missing line breakers in an one-column R dataframe. Those line breakers were missing from the data collection phase.
The data looks like:
V1
Apple
OrangeBanana
BananaBananaBanana
Watermelon
GrapeBanana
so all the line breakers before “Banana” are missing
I want to search for “Banana” and add those missing line breakers so it looks like:
V1
Apple
Orange
Banana
Banana
Banana
Banana
Watermelon
Grape
Banana
Here’s a slightly more general solution, but one that can be easily purposed to explicitly working with “Banana”.
First, let’s split them up by finding all upper case letter which aren’t word boundaries and replacing them with a space and an upper case letter:
Then split by the space character and convert from list to vector:
Or in one line:
EDIT: For a regex that works explicitly with “Banana”: