I\'m working in R.
I have a dataset in which some records contain a list of cities and counties instead of just one city or county. I\'m looking for a way to transpose
d = as.data.frame(do.call(rbind, strsplit(dtaFrame$cityCountry, ",")))
colnames(d) = c("city", "country")
cbind(dtaFrame[,-which(colnames(dtaFrame)=="cityCountry",], d)
should do it.
You can use the function colsplit
in package reshape2
:
x <- c("a, b", "c, d", "e")
library(reshape2)
colsplit(x, ",", names=c("City", "County"))
City County
1 a b
2 c d
3 e