Hello R Gurus: I would like to take a character string and split at the $ sign. I thought that strsplit would do it, but here are the results:> vv[1] "whine$ts1"> vv[1] "whine$ts1"> strsplit(vv,"$")[[1]] [1] "whine$ts1" Does anyone have any suggestions, please? Thanks, Edna Bell
Try strsplit(vv,"$",fixed=TRUE) --- Edna Bell <edna.bell01 at gmail.com> wrote:> Hello R Gurus: > > I would like to take a character string and split at > the $ sign. > > I thought that strsplit would do it, but here are > the results: > > > vv > [1] "whine$ts1" > > vv > [1] "whine$ts1" > > strsplit(vv,"$") > [[1]] > [1] "whine$ts1" > > > Does anyone have any suggestions, please? > > Thanks, > Edna Bell > > ______________________________________________ > R-help at 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. >
On Mon, 22 Oct 2007, Edna Bell wrote:> Hello R Gurus: > > I would like to take a character string and split at the $ sign. > > I thought that strsplit would do it, but here are the results: > >> vv > [1] "whine$ts1" >> vv > [1] "whine$ts1" >> strsplit(vv,"$") > [[1]] > [1] "whine$ts1" > > > Does anyone have any suggestions, please?Study the help page? split: character vector (or object which can be coerced to such) containing regular expression(s) (unless 'fixed = TRUE') to use for splitting. is a big hint to try> vv <- "whine$ts1" > strsplit(vv,"$", fixed=TRUE)[[1]] [1] "whine" "ts1"> > Thanks, > Edna Bell > > ______________________________________________ > R-help at 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.PLEASE do. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On 22 October 2007 at 00:43, Edna Bell wrote: | Hello R Gurus: | | I would like to take a character string and split at the $ sign. | | I thought that strsplit would do it, but here are the results: | | > vv | [1] "whine$ts1" | > vv | [1] "whine$ts1" | > strsplit(vv,"$") | [[1]] | [1] "whine$ts1" | | | Does anyone have any suggestions, please?> strsplit(vv, "\\$")[[1]] [1] "whine" "ts1">strsplit uses so-called regular expressions for which '$' is a meta-character, hence the need for 'escaping' it with a '\', which you then need to escape itself using a second '\'. There are numerous tutorials on regular expressions on the internet you may want to consult. The archives of this mailing also have dozens of posts on it. If you did not try RSiteSearch("strsplit") before posting to the list, consider doing it next time. Hth, Dirk -- Three out of two people have difficulties with fractions.