The Problem:
I am trying to split strings of unorganized baseball player lineups (10 players per lineup) into a data frame of ten organized columns. The problems I'm running into are 1) the order of the positions themselves isn't standard, and 2) the player names have variable formats - some names are "First Last" and others may be "First Last Jr".
The Question:
Is it possible to split these strings (LINEUPS) in a way to get to the organized data frame below (RESULT)?
Input:
LINEUPS <- c('OF Andrew Johnson P Victor Bailey OF Walter Hill 2B Carl Smith 3B Brian Rivera P Joseph Cox 1B Steven Parker SS William Gonzales OF Christopher Taylor C David Washington
',
'SS James Roberts P Dennis Flores OF Jason Torres 2B Jack Rodriguez OF Randy Baker P Edward Anderson C David Washington 3B Thomas Wilson OF Ryan Walker 1B Robert Harris Jr
',
'1B Howard Allen P Philip Hernandez OF Ryan Walker OF Christopher Taylor 2B Jack Rodriguez C Russell James 3B Brian Rivera P Joseph Cox OF Andrew Johnson SS Ralph Martinez
',
'OF Justin Adams P Dennis Flores 1B Jerry Gray P Donald Brooks OF Johnny Lopez 2B Alan Jackson Jr OF Sean Turner C Raymond Stewart SS Ralph Martinez 3B Thomas Wilson
',
'SS Arthur Foster 3B Timothy Mitchell P Joshua Watson OF Johnny Lopez P Edward Anderson C David Washington OF Justin Adams 1B Bruce Bell 2B Jack Rodriguez OF Sean Turner
',
'OF Willie Davis C David Washington P Philip Hernandez SS Ralph Martinez 3B Thomas Wilson OF Johnny Lopez 1B Howard Allen OF George Perez 2B Alan Jackson Jr P Eric Hall
',
'3B Timothy Mitchell P Edward Anderson OF Sean Turner OF Andrew Johnson P Victor Bailey C Paul Robinson SS Ralph Martinez 2B Carl Smith 1B Howard Allen OF Justin Adams
',
'3B Brian Rivera SS Mark Green Jr 1B Robert Harris Jr P Joshua Watson OF Christopher Taylor OF Patrick Perry OF John King 2B Peter Phillips C Terry Scott P Joseph Cox
',
'OF Lawrence Carter 2B Peter Phillips SS Arthur Foster 1B Matthew Campbell P Fred Nelson 3B Jesse Young OF Louis Powell OF Patrick Perry P Philip Hernandez C Terry Scott
',
'1B Jerry Gray OF Willie Davis 2B Alan Jackson Jr 3B Thomas Wilson C Wayne Barnes OF Louis Powell OF Randy Baker P Dennis Flores SS William Gonzales P Fred Nelson
')
Desired Result:
P1 <- c('Victor Bailey','Dennis Flores','Philip Hernandez','Dennis Flores','Joshua Watson','Philip Hernandez','Edward Anderson','Joshua Watson','Fred Nelson','Dennis Flores')
P2 <- c('Joseph Cox','Edward Anderson','Joseph Cox','Donald Brooks','Edward Anderson','Eric Hall','Victor Bailey','Joseph Cox','Philip Hernandez','Fred Nelson')
C <- c('David Washington','David Washington','Russell James','Raymond Stewart','David Washington','David Washington','Paul Robinson','Terry Scott','Terry Scott', 'Wayne Barnes')
"1B" <- c('Steven Parker','Robert Harris Jr', 'Howard Allen','Jerry Gray','Bruce Bell', 'Howard Allen', 'Howard Allen','Robert Harris Jr','Matthew Campbell','Jerry Gray')
"2B" <- c('Carl Smith','Jack Rodriguez','Jack Rodriguez','Alan Jackson Jr','Jack Rodriguez','Alan Jackson Jr','Carl Smith','Peter Phillips','Peter Phillips','Alan Jackson Jr')
"3B" <- c('Brian Rivera','Thomas Wilson','Brian Rivera','Thomas Wilson','Timothy Mitchell','Thomas Wilson','Timothy Mitchell','Brian Rivera','Jesse Young','Thomas Wilson')
SS <- c('William Gonzales','James Roberts','Ralph Martinez','Ralph Martinez','Arthur Foster','Ralph Martinez','Ralph Martinez','Mark Green Jr','Arthur Foster','William Gonzales')
OF1 <- c('Andrew Johnson','Jason Torres','Ryan Walker','Justin Adams','Johnny Lopez', 'Willie Davis','Sean Turner','Christopher Taylor','Lawrence Carter','Willie Davis')
OF2 <- c('Walter Hill','Randy Baker','Christopher Taylor','Johnny Lopez','Justin Adams','Johnny Lopez','Andrew Johnson','Patrick Perry','Louis Powell','Louis Powell')
OF3 <- c('Christopher Taylor','Ryan Walker','Andrew Johnson', 'Sean Turner', 'Sean Turner','George Perez','Justin Adams','John King','Patrick Perry','Randy Baker')
RESULT <- data.frame(P1, P2, C, `1B`, `2B`, `3B`, SS, OF1, OF2, OF3)
Any help and guidance is much appreciated. Thank you!