Ultimately I want to convert this value into as.numeric
but before this I want to replace space for zeros. I do 2 step sub
here as I can do only single space at the time. Can do this in one command?
x <- c(' 3','1 2','12 ') ## could be leading, trailing or in the mid
x
as.numeric(x) ## <@><< NAs introduced by coercion
x <- sub(' ','0',sub(' ','0',x))
as.numeric(x)