Hello, how convert x in xarray (numbers)?> x[1] "0 - 13"> y[1] "11 - 23"> z[1] "220 - 9"> xarray[1] 0 13> yarray[1] 11 23> zarray[1] 220 9 Thanks, RMB
Romildo Martins <romildo.martins <at> gmail.com> writes:> how convert x in xarray (numbers)? > > > x > [1] "0 - 13" > > y > [1] "11 - 23" > > z > [1] "220 - 9" > > xarray > [1] 0 13 > > yarray > [1] 11 23 > > zarray > [1] 220 9Is as.numeric(unlist(strsplit("0 - 13","-"))) what you want?
"Romildo Martins" <romildo.martins at gmail.com> wrote in message news:AANLkTinBiaExcoBZYQDbtr62XR9q=KjVWAAzaQi-kKd0 at mail.gmail.com...> Hello, > > how convert x in xarray (numbers)? > >> x > [1] "0 - 13" >> y > [1] "11 - 23" >> z > [1] "220 - 9" >> xarray > [1] 0 13 >> yarray > [1] 11 23 >> zarray > [1] 220 9 > > > > Thanks, > > RMB >-----------------------------------------------------------------> x <- "0 - 13" > x[1] "0 - 13"> as.numeric(unlist(strsplit(x, "-")))[1] 0 13 HTH
Try f <- function(string) as.numeric(strsplit(string, "- ")[[1]]) f(x) f(y) f(z) HTH, Jorge On Thu, Dec 9, 2010 at 9:24 AM, Romildo Martins <> wrote:> Hello, > > how convert x in xarray (numbers)? > > > x > [1] "0 - 13" > > y > [1] "11 - 23" > > z > [1] "220 - 9" > > xarray > [1] 0 13 > > yarray > [1] 11 23 > > zarray > [1] 220 9 > > > > Thanks, > > RMB > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Try this:
library(gsubfn)
strapply("11 - 23", "\\d{1,3}", simplify = as.numeric)
On Thu, Dec 9, 2010 at 12:24 PM, Romildo Martins
<romildo.martins@gmail.com>wrote:
> Hello,
>
> how convert x in xarray (numbers)?
>
> > x
> [1] "0 - 13"
> > y
> [1] "11 - 23"
> > z
> [1] "220 - 9"
> > xarray
> [1] 0 13
> > yarray
> [1] 11 23
> > zarray
> [1] 220 9
>
>
>
> Thanks,
>
> RMB
>
> ______________________________________________
> 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]]