[R] removing a specific number of digist from a character string

2007-09-17 Thread Kim Milferstedt
Hello, I would like to remove the last 8 digists of character strings in a vector. Below I added a couple of elements from that vector. I have a problem defining a pattern to replace the digits using for example "sub". Removing the ".tif" part works fine using sub('.tif',"",x), but how do I ge

Re: [R] removing a specific number of digist from a character string

2007-09-17 Thread Bert Gunter
D] Subject: Re: [R] removing a specific number of digist from a character string test <- c("060907_17_3_5_1_1_2909.tif", "060907_17_3_5_2_1_2910.tif", "060907_17_3_5_3_1_2911.tif") sub('[[:digit:]][[:digit:]][[:digit:]][[:digit:]]\.tif', '&#x

Re: [R] removing a specific number of digist from a character string

2007-09-17 Thread Jeffrey Robert Spies
For the sake of absolute correctness: > sub('[[:digit:]]{4}\.tif', '', test) should be sub('[[:digit:]]{4}\\.tif', '', test) -- Jeff. On Sep 17, 2007, at 11:59 AM, Jeffrey Robert Spies wrote: > test <- c("060907_17_3_5_1_1_2909.tif", "060907_17_3_5_2_1_2910.tif", > "060907_17_3_5_3_1_2911.tif

Re: [R] removing a specific number of digist from a character string

2007-09-17 Thread Jeffrey Robert Spies
test <- c("060907_17_3_5_1_1_2909.tif", "060907_17_3_5_2_1_2910.tif", "060907_17_3_5_3_1_2911.tif") sub('[[:digit:]][[:digit:]][[:digit:]][[:digit:]]\.tif', '', test) or test <- c("060907_17_3_5_1_1_2909.tif", "060907_17_3_5_2_1_2910.tif", "060907_17_3_5_3_1_2911.tif") sub('[[:digit:]]{4}\.ti

Re: [R] removing a specific number of digist from a character string

2007-09-17 Thread Paul Hiemstra
Hi Kim, You could try: substr("060907_17_3_5_1_1_2909.tif", start = 1, stop = 18) ?substr cheers, Paul Kim Milferstedt schreef: > Hello, > > I would like to remove the last 8 digists of character strings in a > vector. Below I added a couple of elements from that vector. > > I have a problem de