Names <- c("SUSAN,ALTOP","Brent,SPINER","KIM,YAMAGUCHI","John,McMurphy","Kevin,Y")
City <- c("Toronto","New York","Chicago","Toronto","Tokyo")
DF <- data.frame(Names,City)
I'm hoping to create a function that will capitalize the first and last names in the simple example data frame above so that the names read as "Susan Altop","Brent Spiner"...etc. (Notice that I've also removed the commas.)
I can accomplish this using the following codes, either separately or with piping. But I'm hoping to create a function since I'll have to do this many times, but I'm not sure how to do that when using dplyr, tidyr, etc. I'm also open to more creative suggestions that use lists and purrr, if possible.
DF <- DF %>% separate(DF,Names,c("First","Last",sep=","),remove=TRUE)
DF <- DF %>% mutate_each(funs(tolower),First,Last)
DF <- DF %>% mutate_each(funs(Capitalize),First,Last)
DF <- DF %>% mutate(NewNames=paste0(First," ",Last)