[R] cut - strange NA as output

Olivier Crouzet olivier.crouzet at univ-nantes.fr
Tue Oct 6 22:05:45 CEST 2015


Hi,

On Tue, 6 Oct 2015 21:20:13 +0200
Hermann Norpois <hnorpois at gmail.com> wrote:

> Hello,
> 
> why do I get NA for the following:
> 
> cut (x, seq (0, max(x), by=1), label=FALSE)
>  [1] 1322 1175 1155 1149 1295 1173 1289 1197   NA 1129

The NA comes from your max value and it's due to your seq(0, max(x),
by = 1) creating a sequence that will stop BEFORE your decimal max
(x)... Therefore the element of x which equals 1355.888 is not part of
the allowed outputs of cut().

Are you sure you would not rather use either round (x) or ceiling
(x)? Not sure however what you really want from this...

Olivier.

> 
> dput (x)
> c(1321.55376901374, 1174.35657200935, 1154.02042504008,
> 1148.60981925942, 1294.6166388941, 1172.45806806869,
> 1288.31933914639, 1196.26080041462, 1355.88836502166,
> 1128.09901883228)
> 
> Thanks
> Hermann
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


-- 
  Olivier Crouzet, PhD
  Laboratoire de Linguistique -- EA3827
  Université de Nantes
  Chemin de la Censive du Tertre - BP 81227
  44312 Nantes cedex 3
  France

     phone:        (+33) 02 40 14 14 05 (lab.)
                   (+33) 02 40 14 14 36 (office)
     fax:          (+33) 02 40 14 13 27
     e-mail:       olivier.crouzet at univ-nantes.fr
 		
  http://www.lling.univ-nantes.fr/



More information about the R-help mailing list