[R] subsetting character vector into groups of numerics

Ott Toomet siim at obs.ee
Tue Oct 29 07:59:06 CET 2002


On Tue, 29 Oct 2002, Patrick Connolly wrote:

...

  ||> and once we have those we might use scan() on each string to get the
  ||> numbers. This requires the use of a text connection, like this
  ||> 
  ||> > lapply(s[[1]], function(x)scan(textConnection(x)))
  |
  |I'd never had occasion to use textConnection before and was completely
  |ignorant of its existence.  Certainly simpler than my idea of
  |exporting text files and then using a Perl script and then importing
  |back in.

I had used strsplit and as.numeric in that place, e.g.

> a <- c("12 13 14 15 16 888")
> as.numeric(unlist(strsplit(a, " ")))
> [1]  12  13  14  15  16 888

But perhaps Peter's idea is better.

Ott

-- 
Ott Toomet
otoomet at econ.au.dk
---------------------------------------------------------

 (o_         (*_         (O_         (o< -!      (o<)<
//\         //\         //\         //\         //\
V_/_        V_/_        V_/_        V_/_        V_/_

standard    drunken     shocked     noisy      penguin
penguin     penguin     penguin     penguin    eating fish


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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