Hello R-users and developers, Once again, I'm asking for your help. There is other way to do the same more easily for applied simultaneous grep??? c<-subset(c,!rownames(c) %in% grep(".1",rownames(c),value=T)) c<-subset(c,!rownames(c) %in% grep(".5",rownames(c),value=T)) c<-subset(c,!rownames(c) %in% grep(".6",rownames(c),value=T)) c<-subset(c,!rownames(c) %in% grep(".99999",rownames(c),value=T)) Thanks in advance for helping me. Atenciosamente, Ana Patricia Martins ------------------------------------------- Serviço Métodos Estatísticos Departamento de Metodologia Estatística INE - Portugal Telef: 218 426 100 - Ext: 3210 E-mail: ana.pmartins@ine.pt <mailto:ana.pmartins@ine.pt> [[alternative HTML version deleted]]
On Mon, 2007-06-25 at 17:15 +0100, Ana Patricia Martins wrote:> Hello R-users and developers, > > Once again, I'm asking for your help. > > There is other way to do the same more easily for applied simultaneous > grep??? > > c<-subset(c,!rownames(c) %in% grep(".1",rownames(c),value=T)) > c<-subset(c,!rownames(c) %in% grep(".5",rownames(c),value=T)) > c<-subset(c,!rownames(c) %in% grep(".6",rownames(c),value=T)) > c<-subset(c,!rownames(c) %in% grep(".99999",rownames(c),value=T)) > > Thanks in advance for helping me.One question might be what other possible values can the rownames take. For example, if you want to check for '.99999', but not for other values containing a '9' after the decimal, something like the following should work: sub.c <- subset(c, !rownames(c) %in% grep("\\.([156])|([9]{5})", rownames(c), value = TRUE)) Otherwise, if you want to include anything with a '9' after a decimal, the following would work: sub.c <- subset(c, !rownames(c) %in% grep("\\.[1569]", rownames(c), value = TRUE)) See ?regex and the information there for some additional guidance. There are also many regex references online, such as: http://www.regular-expressions.info/ BTW, it would be preferable not to use 'c' to name an object in R, since c() is a function. While conflicts should, in general, not occur, it eliminates such risk and makes for more easily readable code to not use function names for objects. HTH, Marc Schwartz
You can list them together using "|" (which stands for 'or'): c<-subset(c,!rownames(c) %in% grep(".1|.5|.6|.99999",rownames(c),value=T)) but "." means any character for regular expressions, so if you meant a decimal place, you probably want to escape them with a "\\": c<-subset(c,!rownames(c) %in% grep("\\.1|\\.5|\\.6|\\.99999", rownames(c),value=T)) Another option is c<-subset(c,regexpr("\\.1|\\.5|\\.6|\\.99999",c) < 0) because regexpr will return -1 for elements which do not contain a match. --- Ana Patricia Martins <ana.pmartins at ine.pt> wrote:> Hello R-users and developers, > > Once again, I'm asking for your help. > > There is other way to do the same more easily for applied simultaneous > grep??? > > c<-subset(c,!rownames(c) %in% grep(".1",rownames(c),value=T)) > c<-subset(c,!rownames(c) %in% grep(".5",rownames(c),value=T)) > c<-subset(c,!rownames(c) %in% grep(".6",rownames(c),value=T)) > c<-subset(c,!rownames(c) %in% grep(".99999",rownames(c),value=T)) > > Thanks in advance for helping me. > > Atenciosamente, > Ana Patricia Martins > ------------------------------------------- > Servi?o M?todos Estat?sticos > Departamento de Metodologia Estat?stica > INE - Portugal > Telef: 218 426 100 - Ext: 3210 > E-mail: ana.pmartins at ine.pt <mailto:ana.pmartins at ine.pt> > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. >