Re: [R] subseting data

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Mon, 02 May 2011 11:52:14 +0200

On 02.05.2011 11:47, Matevž Pavlič wrote:
> Hi,
>
>
>
> When I use your code i get this :
>
>
>
>> dat<-data.frame(test=c("abc","cdf","dabc"))
>
>> d<-subset(dat,grepl(test,"abc"))

d <- subset(dat, grepl("abc", test))

>
>> d
>
> Warning message:
>
> In grepl(test, "abc") :
>
> argument 'pattern' has length> 1 and only the first element will be used
>
>> d
>
> test
>
> 1 abc
>
> 2 cdf
>
> 3 dabc
>
>
>
> I can't seem to make it work. Also how would i use the grepl() to select only those that are not like i.e. »GP«?

Use the negation:

d <- subset(dat, !grepl("abc", test))

Uwe Ligges

>
>
> Thanks, m
>
>
>
>
>
> From: Steven Kennedy [mailto:stevenkennedy2263_at_gmail.com]
> Sent: Monday, May 02, 2011 11:30 AM
> To: Matevž Pavlič
> Cc: r-help_at_r-project.org
> Subject: Re: [R] subseting data
>
>
>
> You can use grepl:
>
>> dat<-data.frame(test=c("abc","cdf","dabc"))
>> d<-subset(dat,grepl(test,"abc"))
>> d
> test
> 1 abc
> 3 dabc
>
>
>
>
> On Mon, May 2, 2011 at 7:03 PM, Matevž Pavlič<matevz.pavlic_at_gi-zrmk.si> wrote:
>
> Hi,
>
>
>
> Is it possible (i am sure it is) to subset data from a data.frame on the basis of SQL>LIKE< operator. I.e., i would like to subset a data where only values which contains a string>GP< would be used?
>
>
>
> Example:
>
>
>
> Gp<-subset(DF, DF$USCS like>GP<)
>
>
>
> This like of course is not working,
>
>
>
> Thanks, m
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
>
>
>
> [[alternative HTML version deleted]]
>
>
>
>
> ______________________________________________
> 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.



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 Thu 05 May 2011 - 06:25:08 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 Thu 05 May 2011 - 07:00:06 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