Message-ID: <20110403233914.GA8957@master.debian.org>
Date: 2011-04-03T23:39:14Z
From: Dirk Eddelbuettel
Subject: replace last 3 characters of string
In-Reply-To: <000001cbf258$637e5a60$2a7b0f20$@jacobs@figurestofacts.be>
On Mon, Apr 04, 2011 at 01:39:34AM +0200, Bert Jacobs wrote:
> 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.
Keep reading up on regular expressions, this tends to pay off. Here we
use the fact that you can achor a regexp to the end of a string:
R> aString <- "abc:def:::"
R> gsub(":::$", "", aString)
[1] "abc:def"
R>
Hth, Dirk
--
Three out of two people have difficulties with fractions.