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? Regards,
Try this:
str <- " 1975 01 7711.16"
# Find the position of the space in string
gregexpr("[[:space:]]", str)
# Remove the space
gsub("[[:space:]]", "", str)
On Wed, Sep 10, 2008 at 9:07 AM, Megh Dal <megh700004@yahoo.com> 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?
>
> Regards,
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]
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
Is this what you want:> gsub(" ", "", " 1975 01 7711.16")[1] "1975017711.16">On Wed, Sep 10, 2008 at 8:07 AM, Megh Dal <megh700004 at yahoo.com> 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? > > Regards, > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?