Dear, R-lister, I have a dataframe like the followed. And, I want to split a character variable ("popcode", or "codetot") into several new variables. For example, split "BCPy01-01" (in popcode) into "BCPy01" and "01". I need to know how to do that. I have tried strsplit() and substring() functions. But, I still can not perform the spliting.
Any advice? Thanks in advance. df1: popcode codetot p3need BCPy01-01 BCPy01-01-1 100.0000 BCPy01-01 BCPy01-01-2 100.0000 BCPy01-01 BCPy01-01-3 100.0000 BCPy01-02 BCPy01-02-1 92.5926 BCPy01-02 BCPy01-02-1 100.0000 BCPy01-02 BCPy01-02-2 92.5926 BCPy01-02 BCPy01-02-2 100.0000 BCPy01-02 BCPy01-02-3 92.5926 BCPy01-02 BCPy01-02-3 100.0000 BCPy01-03 BCPy01-03-1 100.0000 Regards, Mao Jian-feng [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.