I want to split up the field "Fare_class" on the first space with dropping any fields.I know a similar question exists, but when i tried that approach, it dropped all fields except for "Fare_Class".
Travel_class Fare_class Avios_awarded
First Flexible F 300% of miles flown
First Lowest A 250% of miles flown
Business Flexible J, C, D 250% of miles flown
Business Lowest R, I 150% of miles flown
Below is the table I'd like to create. Splitting "Fare_class" on the first space into two new fields "Fare" and "Booking".
Travel_class Fare_class Fare Booking Avios_awarded
First Flexible F Flexible F 300% of miles flown
First Lowest A Lowest A 250% of miles flown
Business Flexible J, C, D Flexible J,C,D 250% of miles flown
Business Lowest R, I Lowest R,I 150% of miles flown
str_split is used to split the string into (n=) 2 pieces. The output of str_split is a list of 2-element vectors. sapply(..., '[[', ) is used to return the first / second subelement of each list element.