Re: [R] intervals from cut() as numerics?

2006-05-22 Thread Gavin Simpson
On Sat, 2006-05-20 at 15:44 +0200, Dimitrios Rizopoulos wrote: > as an alternative, you can have a look inside cut.default and use the > part that produces the breaks, i.e., > > breaks <- 10 > groups <- cut(x, breaks = breaks) > max.bias <- as.vector(tapply(error, groups, mean)) > > # from cut.d

Re: [R] intervals from cut() as numerics?

2006-05-20 Thread Gabor Grothendieck
Actually here is one further simplification. Here we add the simplify = TRUE to strapply producing an interv which is the transpose of the prior interv and so we modify arrows accordingly. Also suggest you use set.seed when using the random generator so that the example is exactly reproducible.

Re: [R] intervals from cut() as numerics?

2006-05-20 Thread Gabor Grothendieck
One can simplify this slightly using strapply from the gsubfn package. Given groups, this will create interv. strapply applies the indicated function, as.numeric, to each matched pattern, i.e. to each string that represents a number, producing a list of vectors. Then we rbind those vectors togeth

Re: [R] intervals from cut() as numerics?

2006-05-20 Thread Dimitrios Rizopoulos
as an alternative, you can have a look inside cut.default and use the part that produces the breaks, i.e., breaks <- 10 groups <- cut(x, breaks = breaks) max.bias <- as.vector(tapply(error, groups, mean)) # from cut.default() nb <- as.integer(breaks + 1) dx <- diff(rx <- range(x, na.rm = TRUE))

Re: [R] intervals from cut() as numerics?

2006-05-20 Thread Gavin Simpson
On Sat, 2006-05-20 at 17:39 +0800, Berwin A Turlach wrote: > G'day Gavin, > > > "GS" == Gavin Simpson <[EMAIL PROTECTED]> writes: > > GS> The problem is getting the range/interval for each group from > GS> (4,4.3], so I can automate this. > Most likely there is an easier way, but this

Re: [R] intervals from cut() as numerics?

2006-05-20 Thread Berwin A Turlach
G'day Gavin, > "GS" == Gavin Simpson <[EMAIL PROTECTED]> writes: GS> The problem is getting the range/interval for each group from GS> (4,4.3], so I can automate this. Most likely there is an easier way, but this seems to work: ## get the levels of groups: > tmp <- levels(groups) ##

[R] intervals from cut() as numerics?

2006-05-20 Thread Gavin Simpson
Hi, Given some example data: dat <- seq(4, 7, by = 0.05) x <- sample(dat, 30) y <- sample(dat, 30) error <- x - y I have broken the rage of x into 10 groups and I can calculate the bias (mean(error)) for each of these 10 groups: groups <- cut(x, breaks = 10) max.bias <- aggregate(error, list(gr