Re: [R] how to subset rows using regular expression patterns

From: paul sorenson <>
Date: Sun 04 Dec 2005 - 12:20:54 EST

Something like

A[grep('^ab', as.vector(A$M)),]

might work

zhihua li wrote:
> hi netters,
> i have a dataframe A with several columns(variables). the elements of
> column M are character strings. so
> A$M=c("ab","abc","bcd","ac","abcd","fg",....."fl").
> i wanna extract all the rows where A$M match some regular expression
> pattern.
> for a simple example, let the pattern be just "ab", i wanna subset the
> rows where A$M="ab" or "abc" or "abcd" or "abXX".........
> i know i can write a loop,using some regular expression pattern
> functions like grep row by row. but when A's size is pretty large, it's
> inefficient. could anyone give me a hint about a faster code?
> thanks a lot! mailing list PLEASE do read the posting guide! Received on Sun Dec 04 12:29:08 2005

This archive was generated by hypermail 2.1.8 : Sun 04 Dec 2005 - 14:29:32 EST