Re: [R] Cut intervals (character) to numeric midpoint; regex problem

2009-12-01 Thread David Winsemius
On Dec 1, 2009, at 3:28 PM, Gabor Grothendieck wrote: > Try this: > > > library(gsubfn) > > strapply(testvec, "[-+.0-9]+", as.numeric, simplify = ~ > colMeans(cbind(...))) > [1] -5.8500 -2.9800 -2.8160 -2.7120 -2.6325 -2.5680 Very, nice. Also tried on some other valid ("200,2") and invalid )

Re: [R] Cut intervals (character) to numeric midpoint; regex problem

2009-12-01 Thread Gabor Grothendieck
Try this: > library(gsubfn) > strapply(testvec, "[-+.0-9]+", as.numeric, simplify = ~ colMeans(cbind(...))) [1] -5.8500 -2.9800 -2.8160 -2.7120 -2.6325 -2.5680 On Tue, Dec 1, 2009 at 3:14 PM, David Winsemius wrote: > I'm sitting here chuckling. Your solution is just so "pure". > > I would offer

Re: [R] Cut intervals (character) to numeric midpoint; regex problem

2009-12-01 Thread David Winsemius
I'm sitting here chuckling. Your solution is just so "pure". I would offer an enhancement. When I tested with my cuts that had "-" before the digits, you solution dropped them, so my suggestion for the pattern would be: "[-[:digit:].]+" I will admit that I thought it might fail with posit

Re: [R] Cut intervals (character) to numeric midpoint; regex problem

2009-12-01 Thread Henrique Dallazuanna
Perhaps this shoul work too: sapply(strsplit(gsub("^\\W|\\W$", "", testvec), ","), function(x)sum(as.numeric(x))/2) On Tue, Dec 1, 2009 at 5:41 PM, David Winsemius wrote: > Starting with the head of a 499 element matrix whose column names are now > the labels trom a cut() operation, I needed to

Re: [R] Cut intervals (character) to numeric midpoint; regex problem

2009-12-01 Thread Gabor Grothendieck
You also might want to look at demo("gsubfn-cut") On Tue, Dec 1, 2009 at 2:41 PM, David Winsemius wrote: > Starting with the head of a 499 element matrix whose column names are now > the labels trom a cut() operation, I needed to get to a vector of midpoints > to serve as the basis for plotting

[R] Cut intervals (character) to numeric midpoint; regex problem

2009-12-01 Thread David Winsemius
Starting with the head of a 499 element matrix whose column names are now the labels trom a cut() operation, I needed to get to a vector of midpoints to serve as the basis for plotting a calibration curve ( exp(linear predictor) vs. : > dput(head(dimnames(mtcal)[2][[1]])) # was starting po