I am trying (with no success) to split a string at a period. Should I be using a different function? This is my string> x<-"a6502.1"This works fine.> strsplit(x,"2")[[1]] [1] "a650" ".1" This also works fine.> strsplit(x,"1")[[1]] [1] "a6502." But this seems strange> strsplit(x,".")[[1]] [1] "" "" "" "" "" "" "" Niels 0=================================================0 Dr. Niels G. Waller Quantitative Methods Department of Psychology and Human Development Box 512 Peabody College Vanderbilt University Nashville TN 37203 email: niels.waller at vanderbilt.edu fax: 615 343-9494 QME home page: http://www.vanderbilt.edu/quantmetheval http://peabody.vanderbilt.edu/depts/psych_and_hd/faculty/wallern/ 0=================================================0 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 17 Dec 2001, Niels Waller wrote:> I am trying (with no success) to split a string at a period. Should I be > using a different function?<snip>> > strsplit(x,".") > [[1]] > [1] "" "" "" "" "" "" ""No, the problem is that the split argument is a regular expression, not a character string. "." is a regular expression that matches any single character. You want strsplit(x,"\\."), a regular expression that matches only the "." character. This *is* one of the examples in help(strsplit) -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._