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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Coercing character string to function argument ?
3 messages · Derek Eder, Brian Ripley, Adaikalavan Ramasamy
parse is your friend: i <- "1:5, 20:25, 50"
eval(parse(text=paste("c(",i, ")")))
[1] 1 2 3 4 5 20 21 22 23 24 25 50
On Wed, 28 Aug 2002, Derek Eder wrote:
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._