RE: [R] parsing numbers from a string

2004-02-08 Thread Gabor Grothendieck
Try this: sapply( parse( text = chartr( "(],", " +", z ) ), eval ) / 2 chartr translates ( to space, ] to space and comma to +. Then the character strings are parsed and evaluated as R expressions. Finally, we divide by 2. --- Date: Sun, 8 Feb 2004 21:39:13 +0100 From: Jonne Zutt <[EM

RE: [R] parsing numbers from a string

2004-02-08 Thread Liaw, Andy
Here's one possible way: > xrange <- scan("clipboard", what="") Read 7 items > xrange [1] "(0,74.4]" "(74.4,149]" "(149,223]" "(223,298]" "(298,372]" "(372,447]" [7] "(670,744]" > sapply(strsplit(substring(xrange, 2, nchar(xrange)-1), ","), as.numeric) [,1] [,2] [,3] [,4] [,5] [,6] [,7