Re: [R] Subset using grepl

2011-03-17 Thread Kang Min
Ok thank you! On Mar 17, 12:12 pm, wrote: > subset(data,grepl("[1-5]", section) & !grepl("0", section)) > > BTW > > grepl("[1:5]", section) > > does work.  It checks for the characters 1, :, or 5.   > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-proje

Re: [R] Subset using grepl

2011-03-16 Thread Bill.Venables
Kang Min Sent: Thursday, 17 March 2011 1:29 PM To: r-help@r-project.org Subject: Re: [R] Subset using grepl I have a new question, also regarding grepl. I would like to subset rows with numbers from 1 to 5 in the section column, so I used subset(data, grepl("[1:5]", section)) but this ga

Re: [R] Subset using grepl

2011-03-16 Thread Kang Min
I have a new question, also regarding grepl. I would like to subset rows with numbers from 1 to 5 in the section column, so I used subset(data, grepl("[1:5]", section)) but this gave me rows with 10, 1 and 5. (Why is this so?) So I tried subset(data, grepl("[1,2,3,4,5]", section)) which worked.

Re: [R] Subset using grepl

2011-01-29 Thread Prof Brian Ripley
On Sat, 29 Jan 2011, Kang Min wrote: Thanks Prof Ripley, the condition worked! Btw I tried to search ?repl but I don't have documentation for it. Is it in a non-basic package? I meant grepl: the edit messed up (but not on my screen, as sometimes happens when working remotely). The point is t

Re: [R] Subset using grepl

2011-01-29 Thread Kang Min
Thanks Prof Ripley, the condition worked! Btw I tried to search ?repl but I don't have documentation for it. Is it in a non-basic package? On Jan 29, 6:54 pm, Prof Brian Ripley wrote: > The grep comdition is "[A-J]" > > BTW, why there are lots of unnecessary steps here, including using > cbind()

Re: [R] Subset using grepl

2011-01-29 Thread Prof Brian Ripley
The grep comdition is "[A-J]" BTW, why there are lots of unnecessary steps here, including using cbind() and subset(): x <- rep(LETTERS[1:20],3) y <- rep(1:3, 20) z <- paste(x,y, sep="") random.data <- rnorm(60) data <- data.frame(z, random.data) data[grepl("[A-J]", z), ] Now (for the paranoi

[R] Subset using grepl

2011-01-29 Thread Kang Min
Hi all, I would like to subset a dataframe by using part of the level name. x <- rep(LETTERS[1:20],3) y <- rep(1:3, 20) z <- paste(x,y, sep="") random.data <- rnorm(60) data <- as.data.frame(cbind(z, random.data)) I need rows that contain the letters A to J, so I tried: subset(data, grepl(LETTE