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 rb rb 12
rb rj
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 wish to do is
Is this what you want:
x
[1] lema, rb 2% rb 2% rb 3% rb 4%
rb 3% rb 2%,mineuse
[7] rbrbrb 12 rb
rj 30%rb
[13] rbrb 25%rbrb
rbrj, rb
gsub([^0-9]*([0-9]*)[^0-9]*, \\1, x)
[1] 2 2 3
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 3% rb 4% rb 3%
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 '+'
substr(sVec ,start = reVec,
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 :
lema,
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:
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 have a vector of character
] 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
numbers.
A quick example -
extract of the original vector :
lema, rb 2% rb 2% rb 3% rb 4% rb
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 the Help
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:
regexpr(
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
I know that I
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)
[1] 4
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 FAQ and
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
character
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 doesn't
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,
using something
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
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 not contain the
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
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 expressions to
Dear all
I again have a regular expression question. I have this character vector a:
a-c(w AT0a w NN1blockage w CJCand w DT0thatc PUN.,
w AT0a w NN1blockage w CJCand ptr target=KB2LC003w DT0thatc
PUN.,
w AT0a w NN1blockage w CJCandc PUN, w DT0thatc PUN.,
w AT0a w NN1blockage w
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(w AT0a w NN1blockage w CJCand w DT0thatc PUN.,
w AT0a w
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
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\\((.*)\\) ,
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
#
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
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
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
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 not care about
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 ordering of
these two
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
-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@stat.math.ethz.ch
Subject: Re: [R] Regular expressions
Ales Ziberna [EMAIL PROTECTED] writes:
Dear useRs!
I have
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
__
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.character(test$sample.id)
[1] 1.11 10.11
One solution is
test - c(1.11,10.11,11.11,113.31,114.2,114.3)
id - unlist(lapply(strsplit(test,[.]),function(x) {x[2]}))
-Original Message-
From: Bernd Weiss [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 18, 2005 12:10 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Regular
Bernd Weiss bernd.weiss at 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 the . .
Define the dot as
Dirk Eddelbuettel [EMAIL PROTECTED] writes:
Bernd Weiss bernd.weiss at 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
On 18 Aug 2005 at 21:17, Peter Dalgaard wrote:
Dirk Eddelbuettel [EMAIL PROTECTED] writes:
Bernd Weiss bernd.weiss at 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
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
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
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 this is a
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 matched
Sangick Jeon sijeon at 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
program
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
Hi,
Is there a way to use regular expressions to capture
two
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
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
47 matches
Mail list logo