Re: [R] Regexp question

2011-05-04 Thread johannes rara
Thank you all! 2011/5/4 David Wolfskill : > On Wed, May 04, 2011 at 10:41:36PM +0300, johannes rara wrote: >> I have a string like this >> >> st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), >> COUNT(salary), FROM Employees" >> >> How can I remove the last comma before the FROM statement?

Re: [R] Regexp question

2011-05-04 Thread David Wolfskill
On Wed, May 04, 2011 at 10:41:36PM +0300, johannes rara wrote: > I have a string like this > > st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), > COUNT(salary), FROM Employees" > > How can I remove the last comma before the FROM statement? This doesn't use a regex, per se, but: > st <-

Re: [R] Regexp question

2011-05-04 Thread Jerome Asselin
On Wed, 2011-05-04 at 22:41 +0300, johannes rara wrote: > I have a string like this > > st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), > COUNT(salary), FROM Employees" > > How can I remove the last comma before the FROM statement? gsub(",[^,]*FROM ", " FROM ", st) HTH, Jerome __

Re: [R] Regexp question

2011-05-04 Thread Henrique Dallazuanna
Try this: gsub(",\\s+FROM", " FROM", st) On Wed, May 4, 2011 at 4:41 PM, johannes rara wrote: > I have a string like this > > st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), > COUNT(salary), FROM Employees" > > How can I remove the last comma before the FROM statement? > > -J > > _

[R] Regexp question

2011-05-04 Thread johannes rara
I have a string like this st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), COUNT(salary), FROM Employees" How can I remove the last comma before the FROM statement? -J __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo

Re: [R] Regexp question

2010-11-17 Thread Gabor Grothendieck
On Wed, Nov 17, 2010 at 2:59 PM, johannes rara wrote: > I have a vector like this: > > a <- c("thisIsName", "thisIsAlsoName", "andThisName") > > How to break this into pieces and produce a vector with unique parts: > > this > Is > Name > Also > and > This Try this: library(gsubfn) strapply(a, ".

Re: [R] Regexp question

2010-11-17 Thread johannes rara
Great, thanks! 2010/11/17 Henrique Dallazuanna : > Try this: > > Reduce(union, strsplit(gsub("([A-Z])", ";\\1", a), ";")) > > On Wed, Nov 17, 2010 at 5:59 PM, johannes rara > wrote: >> >> I have a vector like this: >> >> a <- c("thisIsName", "thisIsAlsoName", "andThisName") >> >> How to break thi

Re: [R] Regexp question

2010-11-17 Thread Henrique Dallazuanna
Try this: Reduce(union, strsplit(gsub("([A-Z])", ";\\1", a), ";")) On Wed, Nov 17, 2010 at 5:59 PM, johannes rara wrote: > I have a vector like this: > > a <- c("thisIsName", "thisIsAlsoName", "andThisName") > > How to break this into pieces and produce a vector with unique parts: > > this > Is

[R] Regexp question

2010-11-17 Thread johannes rara
I have a vector like this: a <- c("thisIsName", "thisIsAlsoName", "andThisName") How to break this into pieces and produce a vector with unique parts: this Is Name Also and This -J __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/lis

Re: [R] RegExp question

2010-06-16 Thread Andrej
Thanks Romain, works like a charm! Thanks David! Best, Andrej On Jun 16, 10:15 pm, Romain Francois wrote: > Le 16/06/10 18:54, Andrej a écrit : > > > > > Thanks David for your fast reply, but now I realized tat "string" is > > of type: > > >> class(string) > > [1] "jobjRef" > > attr(,"package")

Re: [R] RegExp question

2010-06-16 Thread Romain Francois
Le 16/06/10 18:54, Andrej a écrit : Thanks David for your fast reply, but now I realized tat "string" is of type: class(string) [1] "jobjRef" attr(,"package") [1] "rJava" so I get an error when i try with gsub or sub: sub("^.+\\t(\\d+)\\n.+$", "\\1", string) Error in as.character.default

Re: [R] RegExp question

2010-06-16 Thread David Winsemius
On Jun 16, 2010, at 1:05 PM, Andrej wrote: Sorry, I apologize. Below is the minimal example. library(RWeka) model <- J48(as.factor(Species)~., data = iris) model J48 pruned tree -- Petal.Width <= 0.6: setosa (50.0) Petal.Width > 0.6 | Petal.Width <= 1.7 | | Petal.Lengt

Re: [R] RegExp question

2010-06-16 Thread Andrej
Sorry, I apologize. Below is the minimal example. library(RWeka) model <- J48(as.factor(Species)~., data = iris) > model J48 pruned tree -- Petal.Width <= 0.6: setosa (50.0) Petal.Width > 0.6 | Petal.Width <= 1.7 | | Petal.Length <= 4.9: versicolor (48.0/1.0) | | Petal.L

Re: [R] RegExp question

2010-06-16 Thread David Winsemius
Publicly produce something we can work with. I have no idea how to create an example that will match such an object. ?dput ?dump Read Posting Guide. -- David. On Jun 16, 2010, at 12:54 PM, Andrej wrote: Thanks David for your fast reply, but now I realized tat "string" is of type: class(st

Re: [R] RegExp question

2010-06-16 Thread Andrej
Thanks David for your fast reply, but now I realized tat "string" is of type: > class(string) [1] "jobjRef" attr(,"package") [1] "rJava" so I get an error when i try with gsub or sub: > sub("^.+\\t(\\d+)\\n.+$", "\\1", string) Error in as.character.default(x) : no method for coercing this S4 c

Re: [R] RegExp question

2010-06-16 Thread David Winsemius
On Jun 16, 2010, at 12:04 PM, Andrej wrote: Dear all, I'm trying to filter out the "number of leaves" (it should be 1 in the example below) from the following string: string [1] "Java-Object{J48 pruned tree\n--\n: 0 (15.0/3.0)\n \nNumber of Leaves : \t1\n\nSize of the tree

[R] RegExp question

2010-06-16 Thread Andrej
Dear all, I'm trying to filter out the "number of leaves" (it should be 1 in the example below) from the following string: > string [1] "Java-Object{J48 pruned tree\n--\n: 0 (15.0/3.0)\n \nNumber of Leaves : \t1\n\nSize of the tree : \t1\n}" Any idea how to do that as simple as