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
> 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
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
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 :
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
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
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]*(
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
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
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
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
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
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")
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
>
>
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
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
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
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
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
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
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
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
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
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
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
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
#
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\\((.*)
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
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
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
"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
"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
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
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
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
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
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"
> 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
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
_
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
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
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
>
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
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
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
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
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
47 matches
Mail list logo