On Tue, Dec 11, 2012 at 12:46 PM, Steven Ranney <steven.ran...@gmail.com> wrote:
> All -
>
> I have a column of SiteNames:
>
> SiteName
> OYS-PIA2-FL-1
> OYS-PIA2-LA-1
> OYS-PI-LA-BB-1
> OYS-PIA2-LA-10
> ...
> [truncated]
>
> and I want to include only the last few digits into a new column.
>
> I tried
>
> substr(data$SiteName, 13, 20)
>
> but because some SiteName values are of a different length, the final
> hyphen (i.e., "-") was included:
>
> "1"
> "1"
> "-1"
> "10"

Replace everything up to the last dash with the empty string like this:

sub(".*-", "", data$SiteName)

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help@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.

Reply via email to