I have a data frame with one of the columns consisting of a full_name, instead of this I would like to have a column of firs_name and last_name.
For example: say my data is called datta
head(datta)
full_name V1 V2
lee yees 4 4
jhon morgan 4 5
lebron tom 5 5
I would like to get:
head(datta)
first_name last_name V1 V2
lee yees 4 4
jhon morgan 4 5
lebron tom 5 5
I saw a similar question here in the link
Efficient way to split a vector of a full name in to 2 separate vectors
The only difference is that in that question the names were separated by a comma and in my data it is separated by space. I tried to apply what was shown on the answers just using space instead of a comma.
lst <- strsplit(val.vec,' ')
v1 <- lapply(lst, `[`, 1)
v2 <- lapply(lst, `[`, 2)
It didn't work; it returned a list where each element is one object the first and last name.