1

I want to skip the lines of " 0.00000000E+00 0.00000000E+00 0.00000000E+00" in the data without mentioning the line numbers

x <- readLines(my_data)

My data file contains:

 [14] "  0.1083300029999990  0.1000000049999983  0.0000000000000000   F   F   F"
 [15] "  0.1361099889999977  0.0333300010000031  0.0610700009999974   F   F   F"
 [16] "  0.2458337085981483  0.1596625983837612  0.1201236938314310   T   T   T"
 [17] "  0.1916699980000018  0.1000000049999983  0.0000000000000000   F   F   F" 

[265] "  0.3567308545901469  0.4771083319525928  0.2819153954253011   T   T   T"
[266] "  0.7639834308276008  0.6128812478143999  0.2798895352272694   T   T   T"
[267] "  0.6839739720609472  0.4382156813707780  0.2822545225441857   T   T   T"
[268] "  0.3990199832359380  0.5541038323827081  0.2788781195980334   T   T   T"
[269] "  0.3144960847228617  0.4005890268087597  0.2854107441357669   T   T   T"
[270] " "                                                                       
[271] "  0.00000000E+00  0.00000000E+00  0.00000000E+00"                        
[272] "  0.00000000E+00  0.00000000E+00  0.00000000E+00"                        
[273] "  0.00000000E+00  0.00000000E+00  0.00000000E+00"                        
[274] "  0.00000000E+00  0.00000000E+00  0.00000000E+00" 

I have tried the following way, it skips all the lines. It does not skip the lines from line 271.

skip <- x[-c(grep(0.00000000E+00,x))]

Any suggestion, please.

oguz ismail
  • 1
  • 16
  • 47
  • 69
DS1
  • 35
  • 3
  • > dput(x[265:275, ]) Error in x[265:275, ] : incorrect number of dimensions – DS1 Aug 08 '19 at 06:24
  • > dput(x[265:274, ]) Error in x[265:274, ] : incorrect number of dimensions – DS1 Aug 08 '19 at 06:28
  • `grep("0.00000000E+00", x, fixed=TRUE, invert=TRUE, value=TRUE)`? – Wiktor Stribiżew Aug 08 '19 at 06:51
  • Did my above comment help? If not, please add the output of `dput(droplevels(head(x, 10)))`, or [try other solutions here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to produce a reproducible example. – Wiktor Stribiżew Aug 08 '19 at 10:12
  • Thank you @Wiktor Stribiżew. Yeah, It works.....grep("0.00000000E+00", x, fixed=TRUE, invert=TRUE, value=TRUE) – DS1 Aug 09 '19 at 07:14

1 Answers1

1

You may grep all rows containing 0.00000000E+00 as a literal value and invert the results:

grep("0.00000000E+00", x, fixed=TRUE, invert=TRUE, value=TRUE)

NOTE:

  • fixed=TRUE means the first argument is not a regex, but a fixed, literal string (and thus there is no need worrying about regex special metacharacters)
  • invert=TRUE reverts the result (returns all but those that matched)
  • value=TRUE returns the values.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563