[R] Regex and gsub

arnaud Gaboury arnaud.gaboury at gmail.com
Tue May 11 11:32:00 CEST 2010


TY for the two answers. Both work.




> -----Original Message-----
> From: Phil Spector [mailto:spector at stat.berkeley.edu]
> Sent: Tuesday, May 11, 2010 11:21 AM
> To: arnaud Gaboury
> Cc: r-help at r-project.org
> Subject: Re: [R] Regex and gsub
> 
> df3$DESCRIPTION =
>          sub(' [a-z]{3}/[0-9]{2}','',df3$DESCRIPTION,ignore.case=TRUE)
> 
>  					- Phil Spector
>  					 Statistical Computing Facility
>  					 Department of Statistics
>  					 UC Berkeley
>  					 spector at stat.berkeley.edu
> 
> 
> On Tue, 11 May 2010, arnaud Gaboury wrote:
> 
> > Dear group,
> >
> > Here is my df :
> >
> > df3 <-
> > structure(list(DESCRIPTION = c("COPPER May/10", "COTTON NO.2 Jul/10",
> > "CRUDE OIL miNY May/10", "GOLD Jun/10", "ROBUSTA COFFEE (10) Jul/10",
> > "SOYBEANS Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 May/10",
> > "WHEAT Jul/10", "SPCL HIGH GRADE ZINC USD", "STANDARD LEAD USD",
> > "CORN May/10", "SILVER May/10", "WHEAT May/10", "COFFEE C Jul/10",
> > "CORN Jul/10", "HENRY HUB NATURAL GAS May/10"), POSITION = c(0,
> > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), prix = c(-14,
> > 3.74999999999997, 5.22500000000005, 21.6999999999998, 68, -8.5,
> > 2.72999999999999, -0.900000000000002, -64.25, -41, -118, 7.75,
> > 45.300, 0, 4.75000000000003, -1.5, -0.0490000000000013)), .Names =
> > c("DESCRIPTION",
> > "POSITION", "prix"), row.names = c(NA, -17L), class = "data.frame")
> >
> > I want to remove all the dates in $DESCRIPTION. I was thinking using
> > something like this:
> >> df3$DESCRIPTION<- gsub("here is a regex
> expression","",df3$DESCRIPTION).
> >
> > Can't write the pattern argument in regex.
> >
> > Any help would be appreciated.
> >
> > TY
> >
> >
> > ***************************
> > Arnaud Gaboury
> > Mobile: +41 79 392 79 56
> > BBM: 255B488F
> >
> > ______________________________________________
> > 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.
> >



More information about the R-help mailing list