[R] Coercing character string to function argument ?

Adaikalavan Ramasamy ramasamy at stats.ox.ac.uk
Wed Aug 28 13:45:00 CEST 2002


> indices <- c(1:5, 20:25, 50, 99)
> is.numeric(indices)
[1] TRUE


----- Original Message -----
From: "Derek Eder" <Derek.Eder at neuro.gu.se>
To: "<" <r-help at stat.math.ethz.ch>
Sent: Wednesday, August 28, 2002 12:32 PM
Subject: [R] Coercing character string to function argument ?


> I need to turn the character string:  "1:5, 20:25, 50"  into indices for
subsetting a vector.
>
> For example:
>
> indices <- "1:5, 20:25, 50, 99"
> vector <- rnorm(100,0,1)
>
> # Please R, show me the way to achieve this:  vector[indices]
>
>
> I thank you angels in advance for rushing in where this fool got bogged
down!
>
> - Derek
>
> Derek N. Eder
> Göteborgs Universitet
> Institutionen för klinisk neurovetenskap
> Klinisk Neurofysiologi
> Sahlgrenska universitetssjukhuset SS/SU
> Blå straket 7, vån 3
> SE 413 45  Göteborg
> Sverige
> Tlf. +46 (031) 34  2-6139  (office)
> Tlf. +46 (031) 34 2-1283  (laboratory)
> Tlf. +46 0709 / 7 2-1283 (mobil)
> Fax. +46 (031) 82 81 63
> derek.eder at neuro.gu.se
>
>
> Gothenburg University
> Institute of Clinical Neuroscience,
> Department of Clinical Neurophysiology
> Salhgrenska Hospital  SU/SS
> SE 413 45  Göteborg
> Sweden
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list