Another way you can do it, if the data has the pattern shown in your
sample, it to select all the lines that start with a numeric:
input - FILE-CONTENT ##
+ EXAM NUM:2
+ -
+ EXAM #1
+ ASTIG:-2.4D
+ AXIS:4.8
+ START OF HEIGHT DATA
+ 0 0.0 0.
+ 0 0.1
Hello,
I import datas from an file with: readLines
But I need only a part of all measurments of this file. These are between
two borders START and END.
Can you tell me the syntax of grep(), to choose values between two borders?
My R Code was not succesful, and I can't finde anything in the help.
You can adapt this to your situation:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/22195.html
On 4/17/07, Felix Wave [EMAIL PROTECTED] wrote:
Hello,
I import datas from an file with: readLines
But I need only a part of all measurments of this file. These are between
two borders START and
Hello,
I need to identify all elements which have a sequence of 3 consecutive upper
case letters, anywhere in the string.
I tested my grep expression on this site: http://regexlib.com/RETester.aspx
But when I try it in R, it does not filter anything.
str -c(AGH, this WOUld be good, Not Good at
Try
str[grep('[[:upper:]]{3}',str)]
On 06/11/06, Lapointe, Pierre [EMAIL PROTECTED] wrote:
Hello,
I need to identify all elements which have a sequence of 3 consecutive upper
case letters, anywhere in the string.
I tested my grep expression on this site: http://regexlib.com/RETester.aspx
Quoting David Barron [EMAIL PROTECTED]:
Try
str[grep('[[:upper:]]{3}',str)]
or more efficiently :
grep('[[:upper:]]{3}', str, value = TRUE)
On 06/11/06, Lapointe, Pierre [EMAIL PROTECTED] wrote:
Hello,
I need to identify all elements which have a sequence of 3 consecutive upper
case
ways. Don't expect the RETester to hold the Final Truth; it
seems to relate to a particular programming environment, which is not
R.
grep('[A-Z]{3}', str, perl=TRUE)
[1] 1 2
Not only that, but
grep('[ABCDEFGHIJKLMNOPQRSTUVWXYZ]{3}', str)
[1] 1 2
Hint: What is your collating sequence
Anupam == Anupam Tyagi [EMAIL PROTECTED]
on Mon, 16 Oct 2006 18:15:06 + (UTC) writes:
Anupam Hi Stephane,
Anupam Stéphane CRUVEILLER scruveil at genoscope.cns.fr writes:
is there a way to pass a list of patterns to the grep function? I
vaguely remember something with
Dear R-users,
is there a way to pass a list of patterns to the grep function? I
vaguely remember something with %in% operator...
Thanks,
Stéphane.
--
La science a certes quelques magnifiques réussites à son actif mais
à tout prendre, je préfère de loin être heureux plutôt qu'avoir raison.
Try this:
grep(b|c|d, letters, value = TRUE)
[1] b c d
On 10/16/06, Stéphane CRUVEILLER [EMAIL PROTECTED] wrote:
Dear R-users,
is there a way to pass a list of patterns to the grep function? I
vaguely remember something with %in% operator...
Thanks,
Stéphane.
--
La science a
Thx for the hint, but what would I have used if b,c and d
were values of a dataframe for instance?
Stéphane.
Gabor Grothendieck a écrit :
Try this:
grep(b|c|d, letters, value = TRUE)
[1] b c d
On 10/16/06, Stéphane CRUVEILLER [EMAIL PROTECTED] wrote:
Dear R-users,
is there a way to pass
Ooops sorry for html tags... Just forgot to edit the message
before sending it...
So back to my question:
Thx for the hint, but what would I have used if b,c and d
were values of a dataframe for instance?
X is for instance a dataframe:
X
Mypatterns
1 pattern1
2 pattern2
3 pattern3
Y
DF - data.frame(pat = letters[1:3])
grep(paste(DF$pat, collapse = |), letters, value = TRUE)
[1] a b c
On 10/16/06, Stéphane CRUVEILLER [EMAIL PROTECTED] wrote:
Ooops sorry for html tags... Just forgot to edit the message
before sending it...
So back to my question:
Thx for the hint, but
Hi Stephane,
Stéphane CRUVEILLER scruveil at genoscope.cns.fr writes:
is there a way to pass a list of patterns to the grep function? I
vaguely remember something with %in% operator...
I think you are looking for the %in% and %nin% which are part of Design package,
and also in Hmisc library.
This finds the matching indices of Farrah and Common and then create a
set that does not include them:
x - c('Farrah', 'more', 'Common', 'last')
got.F - grep('Farrah',x)
got.C - grep('Common', x)
not.ForC - setdiff(seq(along=x), c(got.F, got.C))
x[not.ForC]
[1] more last
On 8/31/06, Bob
Or using the same x:
setdiff(x, grep(Farrah|Common, x, value = TRUE))
[1] more last
On 8/31/06, jim holtman [EMAIL PROTECTED] wrote:
This finds the matching indices of Farrah and Common and then create a
set that does not include them:
x - c('Farrah', 'more', 'Common', 'last')
got.F -
You have to be careful if the strings are embedded:
x - c('xxxFarrahxxx' ,'more than last time', 'some Common numbers', 'last
one')
setdiff(x, grep('Farrah|Common', x)) # not correct
[1] xxxFarrahxxxmore than last time some Common numbers
last one
ForC - grep('Farrah|Common', x)
Forget the last reply. I left the 'value=TRUE' off the grep.
x - c('xxxFarrahxxx' ,'more than last time', 'some Common numbers', 'last
one')
setdiff(x, grep('Farrah|Common', x, value=TRUE))
[1] more than last time last one
ForC - grep('Farrah|Common', x)
x[setdiff(seq(along=x), ForC)]
[1]
Dear Denis,
I don't believe that anyone fielded your question -- my apologies if I
missed a response.
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Denis Chabot
Sent: Monday, July 25, 2005 9:46 PM
To: R list
Subject: [R] grep help needed
Hi
list
Subject: [R] grep help needed
Hi,
In another thread (PBSmapping and shapefiles) I asked for an easy
way to read shapefiles and transform them in data that PBSmapping
could use. One person is exploring some ways of doing this,
but it is
possible I'll have to do this manually
Hi,
In another thread (PBSmapping and shapefiles) I asked for an easy
way to read shapefiles and transform them in data that PBSmapping
could use. One person is exploring some ways of doing this, but it is
possible I'll have to do this manually.
With package maptools I am able to extract
hi,
using the example in the grep help:
txt - c(arm,foot,lefroo, bafoobar)
i - grep(foo,txt); i
[1] 2 4
but how can i get the negation (1,3) when looking for 'foo'?
thanks,
m.
__
R-help@stat.math.ethz.ch mailing list
:
[EMAIL PROTECTED]Subject: [R] grep negation
ath.ethz.ch
://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
- Original Message -
From: Marcus Leinweber [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Thursday, June 23, 2005 2:59 PM
Subject: [R] grep negation
hi,
using the example in the grep help:
txt - c(arm,foot,lefroo, bafoobar
If all you need to do is extract the subset of elements of txt that
do not contain 'foo', then
txt[-i]
will do the job. Provided that at east one element of txt contains
'foo', that is.
-Don
At 2:59 PM +0200 6/23/05, Marcus Leinweber wrote:
hi,
using the example in the grep help:
txt -
Hi,
I want to use the first digit of the elements of a vector.
I've tried grep but didn't work.
Any help is welcome.
Thanks
EJ
grep(^[0-9],as.character(runif(100,0,2)))
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18
[19] 19 20 21 22 23 24 25 26 27
Ernesto Jardim wrote:
I want to use the first digit of the elements of a vector.
I've tried grep but didn't work.
Any help is welcome.
substr(as.character(runif(100,0,2)), 1, 1)
see ?substr
--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495
Ernesto Jardim wrote:
Hi,
I want to use the first digit of the elements of a vector.
I've tried grep but didn't work.
Any help is welcome.
Thanks
EJ
grep(^[0-9],as.character(runif(100,0,2)))
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18
[19] 19 20 21
On Fri, 2004-03-12 at 11:08, Ernesto Jardim wrote:
Hi,
I want to use the first digit of the elements of a vector.
I've tried grep but didn't work.
Any help is welcome.
Thanks
EJ
grep(^[0-9],as.character(runif(100,0,2)))
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13
Ernesto -
Use as.numeric(substr(as.character(x), 1, 1)).
- tom blackwell - u michigan medical school - ann arbor -
On Fri, 12 Mar 2004, Ernesto Jardim wrote:
Hi,
I want to use the first digit of the elements of a vector.
I've tried grep but didn't work.
Any help is welcome.
as.integer(x/10^(as.integer(log10(x
-Original Message-
From: Ernesto Jardim [mailto:[EMAIL PROTECTED]
Sent: Friday, March 12, 2004 12:08 PM
To: Mailing List R
Subject: [R] grep
Hi,
I want to use the first digit of the elements of a vector.
I've tried grep but didn't work.
Any
Simon Fear [EMAIL PROTECTED] writes:
The following code works, to gsub single quotes to double quotes:
line - gsub(', '', line)
(that's a single quote within doubles then a double within singles if
your
viewer's font is not good).
But The R Language Manual tells me that
Quotes and
The following code works, to gsub single quotes to double quotes:
line - gsub(', '', line)
(that's a single quote within doubles then a double within singles if
your
viewer's font is not good).
But The R Language Manual tells me that
Quotes and other special characters within strings
are
the
examples posted will be of as much use to others as they are to me.)
Simon
-Original Message-
From: Prof Brian Ripley [mailto:[EMAIL PROTECTED]
Sent: 12 August 2003 17:13
To: Simon Fear
Cc: [EMAIL PROTECTED]
Subject: Re: [R] grep and gsub on backslash and quotes
Security
On Tue, 12 Aug 2003, Simon Fear wrote:
The following code works, to gsub single quotes to double quotes:
line - gsub(', '', line)
(that's a single quote within doubles then a double within singles if
your
viewer's font is not good).
But The R Language Manual tells me that
Quotes
35 matches
Mail list logo