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 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]]
Because > tail(seq(0, max(x), by=1)) [1] 1350 1351 1352 1353 1354 1355 > tail(seq(0, ceiling(max(x)), by=1)) [1] 1351 1352 1353 1354 1355 1356 and max(x)=1355.88836502166 is beyond the range of the former. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Oct 6, 2015 at 12:20 PM, 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 > > 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.
> On Oct 6, 2015, at 2:20 PM, 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 > > 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> max(x)[1] 1355.888> range(seq(0, max(x), by = 1))[1] 0 1355 max(x) is outside (above) the range of the integer sequence of break points for cut() that you specified above. Thus, when cut() gets to the 9th element in x, the value is undefined.> cut (x, seq(0, max(x) + 1, by = 1), label=FALSE)[1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129 or> cut (x, seq(0, ceiling(max(x)), by = 1), label=FALSE)[1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129 Both of the above approaches will increment the sequence 0:max(x) to 1356:> range(seq(0, max(x) + 1, by = 1))[1] 0 1356> range(seq(0, ceiling(max(x)), by = 1))[1] 0 1356 Regards, Marc Schwartz
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 1129The 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/
Thanks this was very helpful. @Olivier Crouzet: Yes, round (x) would do the job but it was a principal confusion ... 2015-10-06 21:57 GMT+02:00 Marc Schwartz <marc_schwartz at me.com>:> > > On Oct 6, 2015, at 2:20 PM, 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 > > > > 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 > > > > max(x) > [1] 1355.888 > > > range(seq(0, max(x), by = 1)) > [1] 0 1355 > > > max(x) is outside (above) the range of the integer sequence of break > points for cut() that you specified above. Thus, when cut() gets to the 9th > element in x, the value is undefined. > > > cut (x, seq(0, max(x) + 1, by = 1), label=FALSE) > [1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129 > > or > > > cut (x, seq(0, ceiling(max(x)), by = 1), label=FALSE) > [1] 1322 1175 1155 1149 1295 1173 1289 1197 1356 1129 > > > Both of the above approaches will increment the sequence 0:max(x) to 1356: > > > range(seq(0, max(x) + 1, by = 1)) > [1] 0 1356 > > > range(seq(0, ceiling(max(x)), by = 1)) > [1] 0 1356 > > > Regards, > > Marc Schwartz > >[[alternative HTML version deleted]]