Skip to content
Prev 366862 / 398502 Next

lines those not started with "rs"

Rui, et. al.:

**IF** the data set can be read into R (3e6 lines x ?bytes/line ??) ,
then I think for a completely specified regular pattern such as that
described by the OP, grep would be a bit inefficient. If x is a vector
of strings, and you wish to remove all those that don't begin with
"rs" then:

 x[!substring(x,1,2) == "rs"]

took about 1/2 the time on my computer as the grepl() version for a
vector,x, of length 1e6.

To be fair, I suspect this may be a negigible difference, as most of
the time would probably be taken in extracting and replacing rows from
the data frame. Nevertheless, it seems worthwhile to highlight the use
of simple, efficient, albeit limited, tools when they *can* be used.

All, of course, assuming I have understood the query correctly.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Jan 30, 2017 at 8:59 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote: