Displaying 1 result from an estimated 1 matches for "splitpop".
Did you mean:
splitpos
2009 Apr 10
4
split a character variable into several character variable by a character
...ar Mao Jianfeng,
"r-help-owner" is not the place for help, but:
r-help at r-project.org
(CC-ed here)
In any case, strsplit() does the job, i.e.:
> unlist(strsplit("BCPy01-01", "-"))
[1] "BCPy01" "01"
You can work with the whole variable, like:
splitpop <- strsplit(df1$popcode, "-")
then access the first part with
> unlist(lapply(splitpop, "[", 1))
[1] "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01" "BCPy01"
[9] "BCPy01&...