[R] Using grep() to subset lines of text

From: ppaarrkk <simon_ecc_at_yahoo.co.uk>
Date: Sat, 29 Nov 2008 04:00:43 -0800 (PST)

I have two vectors, a and b. b is a text file. I want to find in b those elements of a which occur at the beginning of the line in b. I have the following code, but it only returns a value for the first value in a, but I want both. Any ideas please.

a = c(2,3)

b = NULL

b[1] = "aaa 2 aaa"
b[2] = "2 aaa"
b[3] = "3 aaa"
b[4] = "aaa 3 aaa"

grep(paste("^",a, sep=""), b )

-- 
View this message in context: http://www.nabble.com/Using-grep%28%29-to-subset-lines-of-text-tp20746365p20746365.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org 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.
Received on Sat 29 Nov 2008 - 12:05:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 02 Dec 2008 - 10:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive