[R] how to extract characters from a character string

Gabor Grothendieck ggrothendieck at gmail.com
Fri Feb 8 22:41:15 CET 2008


Match the start (^) followed by anything (.*)
to the question mark ([?]) or (|) a space ( ) followed
by anything (.*) to the end ($) and replace each
of those with nothing ("").

gsub("^.*[?]| .*$", "", "32?35.421 N")


On Feb 8, 2008 3:36 PM, Weidong Gu <wgu at uab.edu> wrote:
> Hi, I ran into a problem when I complied a dataset with UTM coordinates.
> For calculating distances between sites, I need to reformat the
> coordinates from, for example,
>
>
>
> 32?35.421 N, to 35.421, i.e. I need to delete all digits before symbol ?
> and a space and N at the end of the string. What functions I should use?
>
>
>
>
> Thanks in advance.
>
>
>
>
>
> Weidong Gu,
>
> Department of Medicine
> University of Alabama, Birmingham
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list