Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (50.2k points)

I am having a confusing example, can someone explain me the below code.

Create a list of data for test.

x <- c(0, 0.01, 0.5, 0.99, 1)

b <- c(0, 0, 1, 1)

Here comes the confusion.

.bincode(x, b, FALSE)

It returns with 2  2  2  2 NA.

But according to the usage, .bincode(x, breaks, right = TRUE, include.lowest = FALSE), .bincode(x, b, FALSE) equals to .bincode(x, b, right = FALSE, include.lowest = FALSE), which means the x should be mapped into NA, 2, 2, 2, 3.

1 Answer

0 votes
by (107k points)

In the R programming, the bins should be:

empty, [0, 1), empty

An input can only be a zero-length interval if it is closed at both ends. Since you have include.lowest = FALSE, nothing can fall in your 0,0 or 1,1 intervals, so they are empty. Everything except 1 falls in the middle bin (bin 2); 1 falls in no bin, so it gets NA.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...