[R] gsub to manipulate characters

Berend Hasselman bhh at xs4all.nl
Fri Feb 24 12:54:15 CET 2012


On 24-02-2012, at 12:48, syrvn wrote:

> Hello,
> 
> from a vector of strings I want to delete everything after the _
> 
>> v <- c("AAA_BB", "FF_MM")
>> gsub("_*", "", v)
> [1] "AAABB" "FFMM" 
> 
> 
> but should be
> [1] "AAA" "FF" 
> 
> 
> Why does * not work? Even perl=TRUE does not give me the right result
> 
gsub("_.*$", "", v)

Berend



More information about the R-help mailing list