R-help, I want to remove the following strings "cpue" and "nogd" string <- c("upsanogd" , "toskanogd" , "hysunogd" , "konganogd" ,"gullaksnogd" , "longunogd" , "blalongunogd" , "brosmunogd") I could use first : first <- gsub("cpue" , "", string) and then : second <- gsub("nogd" , "", first) Can it be done at once? Thanks in advance> version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.0 year 2006 month 10 day 03 svn rev 39566 language R version.string R version 2.4.0 (2006-10-03)>
On 11/15/2006 8:29 AM, Luis Ridao Cruz wrote:> R-help, > > I want to remove the following strings > "cpue" and "nogd" > > string <- c("upsanogd" , "toskanogd" , "hysunogd" , "konganogd" > > ,"gullaksnogd" , "longunogd" , "blalongunogd" , "brosmunogd") > > I could use first : first <- gsub("cpue" , "", string) > and then : second <- gsub("nogd" , "", first) > > Can it be done at once?gsub("cpue|nogd", "", string) See ?regex for a description of the kinds of patterns R can use, in particular "Two regular expressions may be joined by the infix operator |; the resulting regular expression matches any string matching either subexpression. For example, abba|cde matches either the string abba or the string cde. Note that alternation does not work inside character classes, where | has its literal meaning." Duncan Murdoch
Is this what you want? : gsub("cpue\|nogd", "", string) John --- Web sites: www.ifr.ac.uk www.foodandhealthnetwork.com -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Luis Ridao Cruz Sent: 15 November 2006 13:29 To: r-help at stat.math.ethz.ch Subject: [R] gsub R-help, I want to remove the following strings "cpue" and "nogd" string <- c("upsanogd" , "toskanogd" , "hysunogd" , "konganogd" ,"gullaksnogd" , "longunogd" , "blalongunogd" , "brosmunogd") I could use first : first <- gsub("cpue" , "", string) and then : second <- gsub("nogd" , "", first) Can it be done at once? Thanks in advance> version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.0 year 2006 month 10 day 03 svn rev 39566 language R version.string R version 2.4.0 (2006-10-03)>______________________________________________ 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.