[R] cutting out numbers from vectors

Hans-Jörg Bibiko bibiko at eva.mpg.de
Sat Jun 21 11:47:28 CEST 2008


On 20.06.2008, at 19:27, calundergrad wrote:

>
> i have a vector with a string of number
> e.g
>
> [1] 01130010000 001130011000 001130012000 001130013000 001130016000
> [6] 001130018000
>
> i want a vector with the same numbers except with the last three  
> digits  of
> every factor cut off.
> e.g
>
> [1] 01130010 001130011 001130012 001130013 001130016
> [6] 001130018
>
> how do i accomplish this?

One way:

gsub("(.*)(.{3})", "\\1", YOUR_VECTOR)


--Hans



More information about the R-help mailing list