I'm working on some stuff for my fantasy football league. I populate a series of data frames, each named for the position (e.g., QB for quarterbacks, RB for running backs, etc.)
I've been able to use the apply() function to do a lot with rbinding the separate chunks of a position into a single dataframe, but what I'd really like to do is to strip out some text from something for each position.
So I have a dataframe named QB, and one of the columns is called Player, that has some superfluous text I'd like to remove.
So, if I were to do this, it works:
thePosNick <- "QB"
thePlayer <- paste(thePosNick, "$Player", sep="")
g <- str_replace(eval(parse(text=thePlayer)), "remove this text", "")
g <- str_replace(g, "more meaningless text", "")
g <- str_trim(g)
#expected behavior:
QB$Player <- g
That works fine, however, I'd love to be able to do this dynamically, and doing the following doesn't seem to work:
thePosNick <- "QB"
thePlayer <- paste(thePosNick, "$Player", sep="")
g <- str_replace(eval(parse(text=thePlayer)), "remove this text", "")
g <- str_replace(g, "more meaningless text", "")
g <- str_trim(g)
#but i'd love to be able to do something like this:
assign(thePlayer, value=g)
Can anyone tell me what I'm doing wrong? Any suggestions are greatly appreciated, thanks!