An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110502/09e97187/attachment.pl>
subseting data
5 messages · Matevz Pavlic, Steven Kennedy, Andrew Robinson +1 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110502/c30a24cf/attachment.pl>
I wonder if grep() will help you? Cheers Andrew
On Mon, May 02, 2011 at 11:03:52AM +0200, Matev? Pavli? 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.
Andrew Robinson Program Manager, ACERA Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia (prefer email) http://www.ms.unimelb.edu.au/~andrewpr Fax: +61-3-8344-4599 http://www.acera.unimelb.edu.au/ Forest Analytics with R (Springer, 2011) http://www.ms.unimelb.edu.au/FAwR/ Introduction to Scientific Programming and Simulation using R (CRC, 2009): http://www.ms.unimelb.edu.au/spuRs/
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110502/e8b52f3c/attachment.pl>
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.