[R] cut2 error

David Winsemius dwinsemius at comcast.net
Wed Oct 17 22:58:53 CEST 2012


On Oct 17, 2012, at 1:52 PM, Charles Determan Jr wrote:

> Hi A.K.
>
> I tried your code exactly as you presented but I only get the  
> following
> output, did I somehow miss something?  Was there something else  
> loaded?
> Thanks,
>
> [1] [96, 99) [96, 99) [96, 99) [96, 99) [96, 99) 99       [96, 99)  
> [96, 99)
> [9] 99       [96, 99) 99       [96, 99) [96, 99) [96, 99) [96, 99)  
> [96, 99)
> [17] 99       [96, 99) [96, 99) [96, 99) [96, 99) 99       [96, 99)  
> [96, 99)
> [25] 99       99       [96, 99) 99       [96, 99) 99       99       99
> [33] 99       [96, 99) 99       [96, 99) 99       [96, 99) [96, 99) 99
> [41] [96, 99) [96, 99) 99       99       [96, 99) 99       99        
> [96, 99)
> [49] [96, 99) [96, 99) 99       99       [96, 99) [96, 99) [96, 99)  
> [96, 99)
> [57] [96, 99) [96, 99) [96, 99) 99       99       [96, 99) 99       99
> [65] [96, 99) [96, 99) 99       99       [96, 99) [96, 99) [96, 99)  
> [96, 99)
> [73] 99       [96, 99) [96, 99) [96, 99) 99       [96, 99) [96, 99)
> Levels: [96, 99) 99
> Warning message:
> In min(xx[xx > upper]) : no non-missing arguments to min; returning  
> Inf
>
For the quantiles requested with your data you get:

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

So you only have 2 groups in your answer. Why are you persisting in  
trying to do this operation when you only had 4 values to start with?

-- 
David.
>
> On Wed, Oct 17, 2012 at 3:30 PM, arun <smartpink111 at yahoo.com> wrote:
>
>> Hi,
>> Try this:
>> dat1<-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")
>> unique(dat1[,1])
>> #[1] 97 98 99 96 NA
>> dat2<-dat1[!is.na(dat1)]
>> cut2(dat2,g=4)
>> # [1] (96,97]   (96,97]   (97,98]   (97,98]   (96,97]   (98,99]    
>> (96,97]
>> #[8] (97,98]   (98,99]   (97,98]   (98,99]   (97,98]   (97,98]    
>> (96,97]
>> #[15] (96,97]   (97,98]   (98,99]   (97,98]   (-Inf,96] (97,98]    
>> (97,98]
>> #[22] (98,99]   (97,98]   (97,98]   (98,99]   (98,99]   (97,98]    
>> (98,99]
>> #[29] (97,98]   (98,99]   (98,99]   (98,99]   (98,99]   (97,98]    
>> (98,99]
>> #[36] (-Inf,96] (98,99]   (97,98]   (97,98]   (98,99]   (96,97]    
>> (97,98]
>> #[43] (98,99]   (98,99]   (96,97]   (98,99]   (98,99]   (97,98]    
>> (97,98]
>> #[50] (97,98]   (98,99]   (98,99]   (97,98]   (97,98]   (97,98]    
>> (97,98]
>> #[57] (97,98]   (97,98]   (97,98]   (98,99]   (98,99]   (97,98]    
>> (98,99]
>> #[64] (98,99]   (97,98]   (97,98]   (98,99]   (98,99]   (96,97]    
>> (97,98]
>> #[71] (97,98]   (97,98]   (98,99]   (97,98]   (97,98]   (97,98]    
>> (98,99]
>> #[78] (97,98]   (97,98]
>> #Levels: (-Inf,96] (96,97] (97,98] (98,99]
>> A.K.
>>
>>
>>
>>
>> ----- Original Message -----
>> From: Charles Determan Jr <deter088 at umn.edu>
>> To: r-help at r-project.org
>> Cc:
>> Sent: Wednesday, October 17, 2012 3:42 PM
>> Subject: [R] cut2 error
>>
>> 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
>>
>> Regards,
>> Charles
>>
>>    [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list