Re: [R] how to extract characters from a character string

From: Jorge Iván Vélez <jorgeivanvelez_at_gmail.com>
Date: Fri, 8 Feb 2008 16:09:55 -0500

Hi Weidong,

It works, but I'm completely sure could be more efficient:

# x is a string
DELETE=function(x){
x=as.character(x)
res=NULL; for(i in 1:nchar(x)) res=c(res,substr(x,i,i)) pos=which(res=="?"|res==" ") # Detecting "?" and " " res2=res[(pos[1]+1):(pos[2]-1)]
k=length(res2)
res3=NULL; for(i in 1:k) res3=paste(res3,res2[i],sep="") as.numeric(RS)
}

> DELETE("32?35.421 N")
[1] 35.421

I hope this helps.

Jorge

On 2/8/08, 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.

        [[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. Received on Fri 08 Feb 2008 - 21:37:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Feb 2008 - 22:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive