Say I have a vector of peoples' names in my dataframe:
names <- c("Bernice Ingram", "Dianna Dean", "Philip Williamson", "Laurie Abbott",
"Rochelle Price", "Arturo Fisher", "Enrique Newton", "Sarah Mann",
"Darryl Graham", "Arthur Hoffman")
I want to create a vector with the first names. All I know about them is that they come first in the vector above and that they're followed by a space. In other words, this is what I'm looking for:
"Bernice" "Dianna" "Philip" "Laurie" "Rochelle"
"Arturo" "Enrique" "Sarah" "Darryl" "Arthur"
I've found a similar question here, but the answers (especially this one) haven't helped much. So far, I've tried a couple of variations of function from the grep
family, and the closest I could get to something useful was by running strsplit(names, " ")
to separate first names and then strsplit(names, " ")[[1]][1]
to get just the first name of the first person. I've been trying to tweak this last command to give me a whole vector of first names, to no avail.