[R] How to find where is the <space> in data

Marc Schwartz marc_schwartz at comcast.net
Wed Sep 10 14:14:30 CEST 2008


on 09/10/2008 07:07 AM Megh Dal wrote:
> I have following
> 
> " 1975 01 7711.16"
> 
> Here I need to identify where the <space> is there and then
> concatenate rest of the digits without <space>, i.e. I want to have
> "1975017711.16". Is there any R function?


See ?gsub:

# Strip out blanks
> gsub(" ", "", " 1975 01 7711.16")
[1] "1975017711.16"

# Strip out non-numeric or decimal
> gsub("[^0-9\\.]", "", " 1975 01 7711.16")
[1] "1975017711.16"


HTH,

Marc Schwartz



More information about the R-help mailing list