[R] cut2 once, bin twice...

Frank E Harrell Jr f.harrell at vanderbilt.edu
Fri Oct 23 23:29:08 CEST 2009


sdanzige wrote:
> 
> sdanzige wrote:
>>
>> Thank you, but the regular expression example doesn't seem to work
>> correctly.
>>
>>
> 
> I wrote a regular expression that does seem to work, so I'll post it here
> for anyone else that needs it.
> 
> labs<-levels(df$p_bin)
> cbind(lower=as.numeric(sub("[[(]","",sub(",.*","",labs))),
>         upper=as.numeric(sub("[])]","",sub("[[(].*, *","",labs))) )
> 
> 
> I fear my inelegance will peg me as a Windows programmer, but so be it... 
> -S

You can also use the onlycuts=TRUE option to cut2 to get the vector of 
cut points, although they are not arranged as a vector of lower and a 
vector of upper values.  It would be easy to customize cut2 to do that.

Frank

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University




More information about the R-help mailing list