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 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 extract the midpoint?
>
> Thanks,
> jose loreto
>
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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. How do i
extract the midpoint?




You might consider starting with hist() instead. Otherwise, how about

mid <- brk[-1] - diff(brk)/2

where brk is the breakpoints used in cut()

--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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, 5, 2, 3, 4, 5, 6, 7)
cut2num(cut(a, 3))

HTH,

baptiste





2009/11/8 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 extract the midpoint?
>
> Thanks,
> jose loreto
>
>
>        [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[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 extract the midpoint?

Thanks,
jose loreto


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.