[R] strsplit

Dirk Eddelbuettel edd at debian.org
Mon Oct 22 15:04:33 CEST 2007


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.



More information about the R-help mailing list