Re: [R] trim function in R

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 25 Jul 2006 - 00:13:20 EST

A . (dot) matches any character and $ matches the end of string so this replaces the last two characters with the empty string:

   sub("..$", "", x)

On 7/24/06, Wade Wall <wade.wall@gmail.com> wrote:
> Hi all,
> I am looking for a function in R to trim the last two characters of an
> 8 character string in a vector. For example, I have the codes
> 37-079-2, 370079-3,37-079-8 and want to trim them to 37-079 by
> removing the last two characters. Is sub the correct function to use,
> and if so how can I specify trimming the last 2 characters? I have
> read the help file, but can't quite figure out how to do it.
> Thanks,
> Wade
>
> ______________________________________________
> R-help@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.
>



R-help@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. Received on Tue Jul 25 00:36:24 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 25 Jul 2006 - 02:19:29 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.