Re: [R] GREP - Choosing values between two borders

2007-04-18 Thread jim holtman
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 0.00055643
+  9 4.9 1.67278117
+  9 5.0 1.74873257
+ 10 0.0 0.
+ 10 0.1 0.00075557
+ 99 5.3 1.94719490
+ END OF HEIGHT DATA
+ X POS:-0.299mm
+ Y POS:0.442mm
+ Z POS:-0.290mm
+ -
+ EXAM #2
+ ASTIG:-2.4D
+ AXIS:4.8
+ START OF HEIGHT DATA
+  0 0.0 0.
+  0 0.1 0.00055643
+  9 4.9 1.67278117
+  9 5.0 1.74873257
+ 10 0.0 0.
+ 10 0.1 0.00075557
+ 99 5.3 1.94719490
+ END OF HEIGHT DATA
+ X POS:-0.299mm
+ Y POS:0.442mm
+ Z POS:-0.290mm
+ "
> x <- readLines(textConnection(input))
> x <- x[grep("^\\s*\\d", x, perl=TRUE)]
> x.in <- scan(textConnection(x), what=0)
Read 42 items
> x.in <- matrix(x.in, ncol=3, byrow=TRUE)
> x.in
  [,1] [,2]   [,3]
 [1,]0  0.0 0.
 [2,]0  0.1 0.00055643
 [3,]9  4.9 1.67278117
 [4,]9  5.0 1.74873257
 [5,]   10  0.0 0.
 [6,]   10  0.1 0.00075557
 [7,]   99  5.3 1.94719490
 [8,]0  0.0 0.
 [9,]0  0.1 0.00055643
[10,]9  4.9 1.67278117
[11,]9  5.0 1.74873257
[12,]   10  0.0 0.
[13,]   10  0.1 0.00075557
[14,]   99  5.3 1.94719490
>
>

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 "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.
>
> Thank's a lot.
>
> Felix
>
>
>
>
> # R-CODE ###
>  file<- "file-content"
>  Measure <- grep("[START-END]",file)
> #Measure <- grep("[START|END]",file)
>
>
>
>  FILE-CONTENT ##
> EXAM NUM:2
> -
> EXAM #1
> ASTIG:-2.4D
> AXIS:4.8
> START OF HEIGHT DATA
>  0 0.0 0.
>  0 0.1 0.00055643
>  9 4.9 1.67278117
>  9 5.0 1.74873257
> 10 0.0 0.
> 10 0.1 0.00075557
> 99 5.3 1.94719490
> END OF HEIGHT DATA
> X POS:-0.299mm
> Y POS:0.442mm
> Z POS:-0.290mm
> -
> EXAM #2
> ASTIG:-2.4D
> AXIS:4.8
> START OF HEIGHT DATA
>  0 0.0 0.
>  0 0.1 0.00055643
>  9 4.9 1.67278117
>  9 5.0 1.74873257
> 10 0.0 0.
> 10 0.1 0.00075557
> 99 5.3 1.94719490
> END OF HEIGHT DATA
> X POS:-0.299mm
> Y POS:0.442mm
> Z POS:-0.290mm
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] GREP - Choosing values between two borders

2007-04-17 Thread Gabor Grothendieck
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 "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.
>
> Thank's a lot.
>
> Felix
>
>
>
>
> # R-CODE ###
>  file<- "file-content"
>  Measure <- grep("[START-END]",file)
> #Measure <- grep("[START|END]",file)
>
>
>
>  FILE-CONTENT ##
> EXAM NUM:2
> -
> EXAM #1
> ASTIG:-2.4D
> AXIS:4.8
> START OF HEIGHT DATA
>  0 0.0 0.
>  0 0.1 0.00055643
>  9 4.9 1.67278117
>  9 5.0 1.74873257
> 10 0.0 0.
> 10 0.1 0.00075557
> 99 5.3 1.94719490
> END OF HEIGHT DATA
> X POS:-0.299mm
> Y POS:0.442mm
> Z POS:-0.290mm
> -
> EXAM #2
> ASTIG:-2.4D
> AXIS:4.8
> START OF HEIGHT DATA
>  0 0.0 0.
>  0 0.1 0.00055643
>  9 4.9 1.67278117
>  9 5.0 1.74873257
> 10 0.0 0.
> 10 0.1 0.00075557
> 99 5.3 1.94719490
> END OF HEIGHT DATA
> X POS:-0.299mm
> Y POS:0.442mm
> Z POS:-0.290mm
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] GREP - Choosing values between two borders

2007-04-17 Thread Felix Wave
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.

Thank's a lot.

Felix




# R-CODE ###
 file<- "file-content"
 Measure <- grep("[START-END]",file)
#Measure <- grep("[START|END]",file)



 FILE-CONTENT ##
EXAM NUM:2
-
EXAM #1
ASTIG:-2.4D
AXIS:4.8
START OF HEIGHT DATA
 0 0.0 0.
 0 0.1 0.00055643
 9 4.9 1.67278117
 9 5.0 1.74873257
10 0.0 0.
10 0.1 0.00075557
99 5.3 1.94719490
END OF HEIGHT DATA
X POS:-0.299mm
Y POS:0.442mm
Z POS:-0.290mm
-
EXAM #2
ASTIG:-2.4D
AXIS:4.8
START OF HEIGHT DATA
 0 0.0 0.
 0 0.1 0.00055643
 9 4.9 1.67278117
 9 5.0 1.74873257
10 0.0 0.
10 0.1 0.00075557
99 5.3 1.94719490
END OF HEIGHT DATA
X POS:-0.299mm
Y POS:0.442mm
Z POS:-0.290mm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.