Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Kuhn, Max
E David Sent: Monday, July 30, 2007 7:59 AM To: r-help@stat.math.ethz.ch Subject: [R] regular expressions : extracting numbers Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is obtain a vector of the same length with just the number

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Jacques VESLOT
> gsub(" ", "", gsub("%", "", gsub("[a-z]", "", c("tr3","jh40%qs dqd" [1] "3" "40" Jacques VESLOT INRA - Biostatistique & Processus Spatiaux Site Agroparc 84914 Avignon Cedex 9, France Tel: +33 (0) 4 32 72 21 58 Fax: +33 (0) 4 32 72 21 84 GOUACHE David a écrit : > Hello all, > > I hav

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Gabor Grothendieck
I assume if you want the "" components to be NA then you really intend the result to be a numeric vector. The following replaces all non-digits with "" (thereby removing them) and then uses as.numeric to convert the result to numeric. Just omit the conversion if you want a character vector result

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Marc Schwartz
On Mon, 2007-07-30 at 13:58 +0200, GOUACHE David wrote: > Hello all, > > I have a vector of character strings, in which I have letters, > numbers, and symbols. What I wish to do is obtain a vector of the same > length with just the numbers. > A quick example - > > extract of the original vector :

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Christian Ritz
Dear David, does the following work for you? sVec <- c("lema, rb 2%", "rb 2%", "rb 3%", "rb 4%", "rb 3%", "rb 2%,mineuse", "rb", "rb", "rb 12", "rb", "rj 30%", "rb", "rb", "rb 25%", "rb", "rb", "rb", "rj, rb") reVec <- regexpr("[[:digit:]]+", sVec) # see ?regex for details on '[:digit:]' and

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Vladimir Eremeev
GOUACHE David wrote: > > Hello all, > > I have a vector of character strings, in which I have letters, numbers, > and symbols. What I wish to do is obtain a vector of the same length with > just the numbers. > A quick example - > > extract of the original vector : > "lema, rb 2%" "rb 2%" "rb

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread jim holtman
Is this what you want: > x [1] "lema, rb 2%" "rb 2%" "rb 3%" "rb 4%" "rb 3%" "rb 2%,mineuse" [7] "rb""rb""rb 12" "rb" "rj 30%""rb" [13] "rb""rb 25%""rb""rb" "rb""rj, rb" > gsub("[^0-9]*(

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Romain Francois
Bonjour David, What about one of these : R> gsub( "[^[:digit:]]", "", x ) or using perl regular expressions: R> gsub( "\\D", "", x, perl = T ) Cheers, Romain GOUACHE David wrote: > Hello all, > > I have a vector of character strings, in which I have letters, numbers, and > symbols. What I w

[R] regular expressions : extracting numbers

2007-07-30 Thread GOUACHE David
Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is obtain a vector of the same length with just the numbers. A quick example - extract of the original vector : "lema, rb 2%" "rb 2%" "rb 3%" "rb 4%" "rb 3%" "rb 2%,mineuse" "rb" "r

Re: [R] : regular expressions: escaping a dot

2007-06-29 Thread S Ellison
EOF from a keyboard on Windows is often Ctrl+Z. But you're right; it's platform dependent. CtrlZ in Unix has less desirable effects on readLines(). And on your running R process... Drat. >>> Peter Dalgaard <[EMAIL PROTECTED]> 29/06/2007 12:42:41 >>> S Ellison wrote: > Wouldn't it be nice if th

Re: [R] : regular expressions: escaping a dot

2007-06-28 Thread Prof Brian Ripley
On Thu, 28 Jun 2007, Peter Dalgaard wrote: > Prof Brian Ripley wrote: >> >> >> This is explained in ?regexp (in the See Also of ?regexpr): >> >> Patterns are described here as they would be printed by 'cat': _do >> remember that backslashes need to be doubled when entering R >> c

Re: [R] : regular expressions: escaping a dot

2007-06-28 Thread Peter Dalgaard
Prof Brian Ripley wrote: > > > This is explained in ?regexp (in the See Also of ?regexpr): > > Patterns are described here as they would be printed by 'cat': _do > remember that backslashes need to be doubled when entering R > character strings from the keyboard_. > > and in the R

Re: [R] : regular expressions: escaping a dot

2007-06-28 Thread Prof Brian Ripley
On Thu, 28 Jun 2007, Wolfram Fischer wrote: > What's really the problem with: > >> regexpr( '\.odt$', "Yodt", perl=TRUE ) > Warning: '\.' is an unrecognized escape in a character string > Warning: unrecognized escape removed from "\.odt$" > [1] 5 > attr(,"match.length")

Re: [R] : regular expressions: escaping a dot

2007-06-28 Thread Tobias Verbeke
Wolfram Fischer wrote: > What's really the problem with: > >> regexpr( '\.odt$', "Yodt", perl=TRUE ) > Warning: '\.' is an unrecognized escape in a character string > Warning: unrecognized escape removed from "\.odt$" > [1] 5 > attr(,"match.length") > [1] 4 > >

[R] : regular expressions: escaping a dot

2007-06-28 Thread Wolfram Fischer
What's really the problem with: > regexpr( '\.odt$', "Yodt", perl=TRUE ) Warning: '\.' is an unrecognized escape in a character string Warning: unrecognized escape removed from "\.odt$" [1] 5 attr(,"match.length") [1] 4 I know that I could use: > regexp

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Stephen Tucker
Thanks guys for the suggestions guys- I come across this problem a lot but now I have many solutions. Thank you, Stephen --- Peter Dalgaard <[EMAIL PROTECTED]> wrote: > Peter Dalgaard wrote: > > Stephen Tucker wrote: > > > >> Dear R-helpers, > >> > >> Does anyone know how to use regular exp

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Tony Plate
I use regexpr() instead of grep() in cases like this, e.g.: x2[regexpr("exclude",x2)==-1] (regexpr returns a vector of the same length as character vector given it, so there's no problem with it returning a zero length vector) -- Tony Plate Peter Dalgaard wrote: > Stephen Tucker wrote: >> Dear

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Peter Dalgaard
Peter Dalgaard wrote: > Stephen Tucker wrote: > >> Dear R-helpers, >> >> Does anyone know how to use regular expressions to return vector elements >> that don't contain a word? For instance, if I have a vector >> x <- c("seal.0","seal.1-exclude") >> I'd like to get back the elements which do n

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread jim holtman
Find the ones that match and then remove them from the full set with 'setdiff'. > x <- c("seal.0","seal.1-exclude") > x.match <- grep("exclude", x) # find matches > x.match [1] 2 > setdiff(seq_along(x), x.match) # exclude the matches [1] 1 > On 4/25/07, Peter Dalgaard <[EMAIL PROTECTED]> wrote

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Peter Dalgaard
Stephen Tucker wrote: > Dear R-helpers, > > Does anyone know how to use regular expressions to return vector elements > that don't contain a word? For instance, if I have a vector > x <- c("seal.0","seal.1-exclude") > I'd like to get back the elements which do not contain the word "exclude", > us

[R] regular expressions with grep() and negative indexing

2007-04-25 Thread Stephen Tucker
Dear R-helpers, Does anyone know how to use regular expressions to return vector elements that don't contain a word? For instance, if I have a vector x <- c("seal.0","seal.1-exclude") I'd like to get back the elements which do not contain the word "exclude", using something like (I know this doe

[R] Regular expressions: retrieving matches depending on intervening strings [Follow-up]

2006-08-16 Thread Stefan Th. Gries
Dear all This is a follow-up to an earlier posting today regarding a regular expression question. In the meantime, this is the best approximation I could come up with and should give you a better idea what I am talking about. a<-c("a blockage and that.", "a blockage and that.", "a blo

[R] Regular expressions: retrieving matches depending on intervening strings

2006-08-16 Thread Stefan Th. Gries
Dear all I again have a regular expression question. I have this character vector a: a<-c("a blockage and that.", "a blockage and that.", "a blockage and, that.", "a blockage and hungry that.") I would like to retrieve those elements of a in which "" and "" are - directly adjace

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

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 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 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\\((.*)

[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

2006-01-11 Thread Ales Ziberna
GET",text))] I was just supriessed that "or" (|) works and "and" (&) does not. Thanks to all! Best, Ales Ziberna -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Taylor, Z Todd Sent: Wednesday, January 11, 2006 7:50 PM To: r-help

Re: [R] Regular expressions

2006-01-11 Thread Ales Ziberna
Thank you! This is definitely an improvement! Best, Ales Ziberna -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Dalgaard Sent: Wednesday, January 11, 2006 7:24 PM To: Ales Ziberna Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Regular

Re: [R] Regular expressions

2006-01-11 Thread Taylor, Z Todd
"Ales Ziberna" <[EMAIL PROTECTED]> writes: > Dear useRs! > > I have the following problem. I would like to find objects in > my environment > that have two strings in it. For example, I might want to > find objects that > have in their names "MY" and "TARGET". I do not care about > the orderin

Re: [R] Regular expressions

2006-01-11 Thread Peter Dalgaard
"Ales Ziberna" <[EMAIL PROTECTED]> writes: > Matching regular expressions > > Dear useRs! > > I have the following problem. I would like to find objects in my environment > that have two strings in it. For example, I might want to find objects that > have in their names "MY" and "TARGET". I do n

[R] Regular expressions

2006-01-11 Thread Ales Ziberna
Matching regular expressions Dear useRs! I have the following problem. I would like to find objects in my environment that have two strings in it. For example, I might want to find objects that have in their names "MY" and "TARGET". I do not care about the ordering of these two substrings in the

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

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 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 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 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

[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 _

RE: [R] Regular Expressions

2004-07-13 Thread Mark.Palmer
PROTECTED] Subject: Re: [R] Regular Expressions Hello, Not really regular expressions but you may also look at the first version of my package ttda at http://wwwpeople.unil.ch/jean-pierre.mueller/ and the functions: ttda.get.text ttda.segmentation ttda.forms.frame ttda.TLE HTH. -- Jean-Pierre

Re: [R] Regular Expressions

2004-07-13 Thread Jean-Pierre Müller
Hello, Not really regular expressions but you may also look at the first version of my package ttda at http://wwwpeople.unil.ch/jean-pierre.mueller/ and the functions: ttda.get.text ttda.segmentation ttda.forms.frame ttda.TLE HTH. -- Jean-Pierre Müller SSP / BFSH2 / UNIL / CH - 1015 Lausanne Voic

Re: [R] Regular Expressions

2004-07-12 Thread John Bullock
rl/ && /prog/) {do something} } But I don't know a simple way to do it in R. --John - Original Message - From: "Sangick Jeon" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, July 12, 2004 4:59 PM Subject: [R] Regular Expressions >

Re: [R] Regular Expressions

2004-07-12 Thread Gabor Grothendieck
Sangick Jeon ucdavis.edu> writes: > Is there a way to use regular expressions to capture two or more words in a > sentence? For example, I wish to to find all the lines that have the words "thomas", > "perl", and "program", such as "thomas uses a program called perl", or "perl is a > progra

Re: [R] Regular Expressions

2004-07-12 Thread Tony Plate
I'd suggest doing it with multiple regular expressions -- you could construct a single regular expression for this, but I expect it would get quite complicated and possibly very slow. The expression for "y" in the example below tabulates how many words matched for each line (i.e., line 2 matche

[R] Regular Expressions

2004-07-12 Thread Sangick Jeon
Hi, Is there a way to use regular expressions to capture two or more words in a sentence? For example, I wish to to find all the lines that have the words "thomas", "perl", and "program", such as "thomas uses a program called perl", or "perl is a program that thomas uses", etc. I'm sure thi

Re: [R] regular expressions in R?

2004-03-04 Thread Christian Schulz
Ann, there is something in base: regexpr(pattern, text, extended = TRUE, perl = FALSE, fixed = FALSE) IMHO show under ?grep christian Am Donnerstag, 4. März 2004 21:12 schrieb Ann Loraine: > Hello! > > Are there any additional packages (besides "regex") I could use to > incorporate regular e

[R] regular expressions in R?

2004-03-04 Thread Ann Loraine
Hello! Are there any additional packages (besides "regex") I could use to incorporate regular expressions in my R code? I would be grateful for any tips or help you could provide! Yours, Ann Loraine __ [EMAIL PROTECTED] mailing list https://www.stat