Re: [R] Obtaining midpoints of class intervals produced by cut and table

2009-11-08 Thread Gabor Grothendieck
Try this: library(gsubfn) demo("gsubfn-cut") and note the strapply call that converts the levels from cut to a matrix. On Sun, Nov 8, 2009 at 4:08 PM, jose romero wrote: > Hello list: > > I am using "cut" and "table" to obtain a frequency table from a numeric > sample vector.  The idea is to c

Re: [R] Obtaining midpoints of class intervals produced by cut and table

2009-11-08 Thread Peter Dalgaard
jose romero wrote: Hello list: I am using "cut" and "table" to obtain a frequency table from a numeric sample vector. The idea is to calculate mean and standard deviation on grouped data. However, I can't extract the midpoints of the class intervals, which seem to be strings treated as factors.

Re: [R] Obtaining midpoints of class intervals produced by cut and table

2009-11-08 Thread baptiste auguie
Hi, Maybe something like this (inspired by ?cut), cut2num <- function(f){ labs <- levels(f) d <- data.frame(lower = as.numeric( sub("\\((.+),.*", "\\1", labs) ), upper = as.numeric( sub("[^,]*,([^]]*)\\]", "\\1", labs) )) d$midpoints <- rowMeans(d) d } a <- c(1, 2, 3, 4

[R] Obtaining midpoints of class intervals produced by cut and table

2009-11-08 Thread jose romero
Hello list: I am using "cut" and "table" to obtain a frequency table from a numeric sample vector.  The idea is to calculate mean and standard deviation on grouped data.  However, I can't extract the midpoints of the class intervals, which seem to be strings treated as factors.  How do i extrac