[R] levels values of cut()

Stephen Tucker brown_emu at yahoo.com
Sat Aug 9 11:10:46 CEST 2008


Not sure what you're looking for, but does this help?

Extending your code,

> library(gsubfn)
> t(strapply(levels(my.cuts),"([0-9.]+),([0-9.]+)",
+          function(...) as.numeric(c(...)),backref=-2,simplify=TRUE))
     [,1] [,2]
[1,] 15.9 38.3
[2,] 38.3 60.7
[3,] 60.7 83.1



----- Original Message ----
From: baptiste auguie <ba208 at exeter.ac.uk>
To: r-help at r-project.org
Sent: Saturday, August 9, 2008 1:51:01 AM
Subject: [R] levels values of cut()

Dear list,

  I have the following example, from which I am hoping to retrieve  
numeric values of the factor levels (that is, without the brackets):

>
> x <- seq(1, 15, length=100)
> y <- sin(x)
>
> my.cuts <- cut(which(abs(y) < 1e-1), 3)
> levels(my.cuts)

hist() does not suit me for this, as it does not necessarily respect  
the number of breaks.

getAnywhere hasn't got me very far: I cannot seem to find a readable  
code for the built-in cut function in the base library. I think  
getMethod should do it but I don't understand the arguments to pass.

Any pointers appreciated,

Thanks,

baptiste



_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

______________________________________________
R-help at 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.







More information about the R-help mailing list