[R] gsub
Jean Eid
jeaneid at chass.utoronto.ca
Thu Sep 23 19:43:16 CEST 2004
Thank you all for the help, specially Gabor that is exactly what I needed.
A few examples that do the same thing is very helpful in understanding the
structure of the call.
Thank you again,
Jean
On Thu, 23 Sep 2004, Gabor Grothendieck wrote:
> Jean Eid <jeaneid <at> chass.utoronto.ca> writes:
>
> :
> : Hi
> :
> : A while back I used gsub to do the following
> :
> : temp<-"000US00231"
> : gsub("something here", "", temp)
> : "00231"
> :
> : I think it involved the `meta characters' somehow.
> :
> : I do not know how to do this anymore. I know strsplit will also work but I
> : remember gsub was much faster. In essence the question is how to delete
> : all characters before a particular pattern.
> :
> : If anyone has some help file for this, it will be greatly appreciated.
> :
>
> I think you want sub in this case, not gsub.
>
> There are many possibilities here depending on what the
> general case is. The following all give the desired
> result for the example but their general cases differ.
> These are just some of the numerous variations possible.
>
> temp<-"000US00231"
> sub(".*US", "", temp)
> sub(".*S", "", temp)
> sub("[[:digit:]]*[[:alpha:]]*", "", temp)
> sub(".*[[:alpha:]]", "", temp)
> sub(".*[[:alpha:]][[:alpha:]]", "", temp)
> sub(".*[[:upper:]]", "", temp)
> sub(".*[[:upper:]][[:upper:]]", "", temp)
> sub(".....", "", temp)
> substring(temp, 6)
>
> ______________________________________________
> 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
>
More information about the R-help
mailing list