I have the following columns in my data set:
presult aresult
I single
I double
I triple
I home run
SS st
An alternative to Dieter's answer:
dat <- data.frame(
presult = c(rep("I", 4), "SS", "ZZ"),
aresult = c("single", "double", "triple", "home run", "strikeout", "home run"),
stringsAsFactors=FALSE
)
dat$base <- as.integer(factor(dat$aresult,
levels=c("strikeout","single","double","triple","home run")))-1