[R] regular expression question
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Mar 3 09:51:31 CET 2009
markleeds at verizon.net wrote:
> can someone show me how to use a regular expression to break the
> string at the bottom up into its three components :
>
> (-0.791,-0.263]
> (-38,-1.24]
> (0.96,2.43]
>
> I tried to use strplit because of my regexpitis ( it's not curable.
> i've been to many doctors all over NYC. they tell me there's no cure
> ) but it doesn't work because there also dots inside the brackets.
> Thanks.
>
> (-0.791,-0.263].(-38,-1.24].(0.96,2.43]
>
here's one way to get a matrix of numeric values:
text = "(-0.791,-0.263].(-38,-1.24].(0.96,2.43]"
values = matrix(ncol=2, byrow=TRUE,
as.numeric(
grep(pattern='.', value=TRUE,
x=strsplit(x=text, split=']\\.\\(|\\(|]|,')[[1]])))
modify any of the steps according to your needs.
vQ
More information about the R-help
mailing list