I have a vector consisting of full names with the first and last name separated by a comma this is what the first few elements look like:
> head(val.vec)
[1] "Aabye,ֲ Edgar" "Aaltonen,ֲ Arvo" "Aaltonen,ֲ Paavo"
[4] "Aalvik Grimsb,ֲ Kari" "Aamodt,ֲ Kjetil Andr" "Aamodt,ֲ Ragnhild
I am looking for a way to split them in to 2 separate columns of first and last name. My final intention is to have both of them as a part of a bigger data frame.
I tried using strsplit
function like this
names<-unlist(strsplit(val.vec,','))
but it gave me one long vector instead of 2 separate sets, I know it is Possible to use a loop and go over all the elements and place the first and last name in 2 separate vectors, but it is a little time consuming considering the fact that there are about 25000 records.
I saw a few similar questions but the discussion was how to do it on C+ and Java
do.call(rbind, strsplit(val.vec, ","))
, only with an unnecessarysapply()
loop. – Briar