[R] Regular expressions & sub

2005-08-18 Thread Bernd Weiss
Dear all, I am struggling with the use of regular expression. I got > as.character(test$sample.id) [1] "1.11" "10.11" "11.11" "113.31" "114.2" "114.3" "114.8" and need [1] "11" "11" "11" "31" "2" "3" "8" I.e. remove everything before the "." . TIA, Bernd _

[R] regular expressions, sub

2006-01-27 Thread Christian Hoffmann
Hi, I am trying to use sub, regexpr on expressions like log(D) ~ log(N)+I(log(N)^2)+log(t) being a model specification. The aim is to produce: "ln D ~ ln N + ln^2 N + ln t" The variable names N, t may change, the number of terms too. I succeded only partially, help on regular express

Re: [R] Regular expressions & sub

2005-08-18 Thread Tony Plate
> x <- scan("clipboard", what="") Read 7 items > x [1] "1.11" "10.11" "11.11" "113.31" "114.2" "114.3" "114.8" > gsub("[0-9]*\\.", "", x) [1] "11" "11" "11" "31" "2" "3" "8" > Bernd Weiss wrote: > Dear all, > > I am struggling with the use of regular expression. I got > > >>as.char

Re: [R] Regular expressions & sub

2005-08-18 Thread bogdan romocea
TECTED] > Sent: Thursday, August 18, 2005 12:10 PM > To: r-help@stat.math.ethz.ch > Subject: [R] Regular expressions & sub > > > Dear all, > > I am struggling with the use of regular expression. I got > > > as.character(test$sample.id) > [1] "1.11"

Re: [R] Regular expressions & sub

2005-08-18 Thread Dirk Eddelbuettel
Bernd Weiss uni-koeln.de> writes: > I am struggling with the use of regular expression. I got > > > as.character(test$sample.id) > [1] "1.11" "10.11" "11.11" "113.31" "114.2" "114.3" "114.8" > > and need > > [1] "11" "11" "11" "31" "2" "3" "8" > > I.e. remove everything before t

Re: [R] Regular expressions & sub

2005-08-18 Thread Peter Dalgaard
Dirk Eddelbuettel <[EMAIL PROTECTED]> writes: > Bernd Weiss uni-koeln.de> writes: > > I am struggling with the use of regular expression. I got > > > > > as.character(test$sample.id) > > [1] "1.11" "10.11" "11.11" "113.31" "114.2" "114.3" "114.8" > > > > and need > > > > [1] "11" "1

Re: [R] Regular expressions & sub

2005-08-18 Thread Bernd Weiss
On 18 Aug 2005 at 21:17, Peter Dalgaard wrote: > Dirk Eddelbuettel <[EMAIL PROTECTED]> writes: > > > Bernd Weiss uni-koeln.de> writes: > > > I am struggling with the use of regular expression. I got > > > > > > > as.character(test$sample.id) > > > [1] "1.11" "10.11" "11.11" "113.31" "114.2

Re: [R] regular expressions, sub

2006-01-27 Thread Prof Brian Ripley
Note that [:alpha:] is a pre-defined character class and should only be used inside []. And metacharacters need to be quoted. See ?regexp. > f <- log(D) ~ log(N)+I(log(N)^2)+log(t) > f1 <- deparse(f) > f1 [1] "log(D) ~ log(N) + I(log(N)^2) + log(t)" Now we have a string. (f2 <- gsub("I\\((.*)

Re: [R] regular expressions, sub

2006-01-27 Thread Philippe Grosjean
Hello, Here is what I got after playing a little bit with your problem: # First of all, if you prefer 'ln' instead of 'log', why not to define: ln <- function(x) log(x) ln2 <- function(x) log(x)^2 ln3 <- function(x) log(x)^3 ln4 <- function(x) log(x)^4 # ... as many function as powers you need #

Re: [R] regular expressions, sub

2006-01-27 Thread paul sorenson
There are some interactive regex tools around. I use a python one sometimes. You just then have to be careful re escaping and the style of regular expressions used in the tool you worked with and the target environment. Christian Hoffmann wrote: > Hi, > > I am trying to use sub, regexpr on e

Re: [R] regular expressions, sub

2006-01-27 Thread Gabor Grothendieck
In this post: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/30590.html Thomas Lumley provided a function to traverse a formula recursively. We can modify it as shown to transform ln(m)^n to ln^n(m) producing proc2. We then bundle everything up into proc3 which uses substitute to transl