[R] cut2 error

David Winsemius dwinsemius at comcast.net
Wed Oct 17 22:18:12 CEST 2012


On Oct 17, 2012, at 12:42 PM, Charles Determan Jr wrote:

> To R users,
>
> I am trying to use cut2 function from the 'Hmisc' library.  However,  
> when I
> try and run the function on the following variable, I get an error  
> message
> (displayed below).  I suspect it is because of the NA but I have no  
> idea
> how to address the error.  Many thanks to any insights.
>
> structure(list(var1 = c(97, 97, 98, 98, 97, 99, 97,
> 98, 99, 98, 99, 98, 98, 97, 97, 98, 99, 98, 96, 98, 98, 99, 98,
> 98, 99, 99, 98, 99, 98, 99, 99, 99, 99, 98, 99, 96, 99, 98, 98,
> 99, 97, 98, 99, 99, 97, 99, 99, 98, 98, 98, 99, NA, 99, 98, 98,
> 98, 98, 98, 98, 98, 99, 99, 98, 99, 99, 98, 98, 99, 99, 97, 98,
> 98, 98, 99, 98, 98, 98, 99, 98, 98)), .Names = "var1", row.names =  
> c(NA,
> 80L), class = "data.frame")
>
> cut2(dat[,1], g=4)
>
> Warning message:
> In min(xx[xx > upper]) : no non-missing arguments to min; returning  
> Inf
>

It's not n error message. You got a factor result. Only a warning.  
What did you expect when you asked for quartiles in a sample that was  
distributed as:

 > table(dat[1])

96 97 98 99
  2  9 39 29

 > quantile(dat[1], prob=(1:3)/4, na.rm=TRUE)
25% 50% 75%
  98  98  99

-- 
David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list