Re: [R] replace last 3 characters of string

From: jim holtman <jholtman_at_gmail.com>
Date: Mon, 04 Apr 2011 00:46:36 -0400

Will this do it for you:

> x <- c('asdfasdf', 'sadfasdf/:/', 'sadf', 'asdf/:/')
> sub("/:/$", '', x)

[1] "asdfasdf" "sadfasdf" "sadf" "asdf"

On Sun, Apr 3, 2011 at 7:39 PM, Bert Jacobs <bert.jacobs_at_figurestofacts.be> wrote:
> Hi,
>
>
>
> I would like to replace the last tree characters of the values of a certain
> column in a dataframe.
>
> This replacement should only take place if the last three characters
> correspond to the value "/:/" and they should be replaced with ""(blank)
>
> I cannot perform a simple gsub because the characters /:/ might also be
> present somewhere else in the string values and then they should not be
> replaced.
>
>
>
> Could someone help me out on this one?
>
> Thx
>
> Bert
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

______________________________________________
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.
Received on Mon 04 Apr 2011 - 04:48:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 04 Apr 2011 - 06:20:27 GMT.

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

list of date sections of archive