Thank you so much! It looks like as.character was the missing ingredient. Neil
On 12/9/06, Chuck Cleland <[EMAIL PROTECTED]> wrote: > > Neil McLeod wrote: > > Hello, > > > > I am having difficulty filtering a data frame. > > > > I would like to take all the rows of a data frame where column A > contains > > the regular expression "UTI" (or some other regex). Here's what I've > got: > > > > utiRE <- function (avector) { > > occurs <- c() > > r1 <- "UTI" > > for (x in avector) { > > if (!is.na(grep(r1,x,perl=TRUE))) { > > occurs <- c(occurs, TRUE) > > } else { > > occurs <- c(occurs, FALSE) > > } > > > > > > I know this is a clunky way of doing it, but I tried more natural ways > first > > (i.e. without iteration), to no avail. I think the problem is that when > I > > iterate through the list, the strings in avector get turned into > numbers. > > > > Any solutions? > > The following approach works for me: > > iris[grep("a$", iris$Species),] > > iris[grep("^v", as.character(iris$Species)),] > > > Thanks! > > -- > Chuck Cleland, Ph.D. > NDRI, Inc. > 71 West 23rd Street, 8th floor > New York, NY 10010 > tel: (212) 845-4495 (Tu, Th) > tel: (732) 512-0171 (M, W, F) > fax: (917) 438-0894 > -- Ubuntu Linux 6.06 (Dapper Drake) [[alternative HTML version deleted]] ______________________________________________ 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.