Truncate A String

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

Source: http://www.r-bloggers.com/truncate-by-delimiter-in-r/

# create some simulated data
patients <- data.frame(
  uid = 1:3,
  fullname = c("Smith/John", "Jackson/Smith", "Joel/Billy"))
patients$lastname <- sub("/.*", "", patients$fullname); patients$lastname
[1] "Smith"   "Jackson" "Joel"