I'm trying to extract semicolon separated values from each row for a particular column in a data frame. See table below
ID Collab City
1 New York;NY;US
2 San Francisco;CA;US
3 Stockholm;Stockholm;SE
I want to be able to extract each value in the Collab column using the semicolon as the separator. I used a for loop to loop through the data frame and trying to update the city and the state columns using the extract strings from the Collab columns. I tried the code below
"dframe" is the name my data frame
#loop code begings
for (row in 1:nrow(dframe)) {
splitText <- as.character (dframe[row,"Collab"])
splitFinal<-strsplit(splitText, ";")
#update column city for that row with extracted value
dframe[row, "City"]<-splitFinal[1]
}
I'm trying to access the position of each string and use it to update the respective column. If there is any post the solves this exact problem, please point to me and I will delete this. I searched extensively but found now answer. Thank you in advance.