Re: [R] regex sub with specified number of characters

2015-10-06 Thread David Winsemius
On Oct 6, 2015, at 7:38 AM, Johannes Radinger wrote: > Hi > > I'd like to remove a leading "3" if my number is 7 digits long, if it is > only 6 I don't want to anything. > I think this should be possible with a 1-liner using sub() but I am not > sure how to define the number of characters follow

Re: [R] regex sub with specified number of characters

2015-10-06 Thread Marc Schwartz
> On Oct 6, 2015, at 9:38 AM, Johannes Radinger > wrote: > > Hi > > I'd like to remove a leading "3" if my number is 7 digits long, if it is > only 6 I don't want to anything. > I think this should be possible with a 1-liner using sub() but I am not > sure how to define the number of character

Re: [R] regex sub with specified number of characters

2015-10-06 Thread Ivan Calandra
Hi Johannes, Not sure if this can be done with sub() only, but combining it with ifelse() apparently does what you want: ifelse(nchar(a)==7, sub("^3","",a), a) HTH, Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims,

[R] regex sub with specified number of characters

2015-10-06 Thread Johannes Radinger
Hi I'd like to remove a leading "3" if my number is 7 digits long, if it is only 6 I don't want to anything. I think this should be possible with a 1-liner using sub() but I am not sure how to define the number of characters following the leading one. For example my vector: a <- c(3593857,384723