I am trying to split the column below using answer First question. For now I am creating the new column in the df by using the letter. I would like to use the Letter before the name as the new column name. In the case below G, D, W, C, UTIL.
Since there are only 'spaces' between the category G
and the names First Person
, etc I am scratching my head as how I could go about seperating the Category G
and both the first and last name and join them under the appropriate column.
library(stringr)
test <- data.frame(Lineup = c("G First Person D Another Last W Fake Name C Test Another UTIL Another Test", "G Fake Name W Another Fake D Third person UTIL Another Name C Name Another "))
1 G First Person D Another Last W Fake Name C Test Another UTIL Another Test
2 G Fake Name W Another Fake D Third person UTIL Another Name C Name Another
test$G <- str_split_fixed(test$Lineup, " ", 2)
result:
G
G
Hopeful Result:
G D W C UTIL
First Person Another Last Fake Name Test Another Another Test
Fake Name Third Person Another Fake Name Another Another Name