search for: zerobased

Displaying 3 results from an estimated 3 matches for "zerobased".

2024 Apr 21
1
x[0]: Can '0' be made an allowed index in R?
...minimal, self-contained, reproducible code. Hello, I find what you are asking awkward but it can be done with S3 classes. Write an extraction method for the new class and in the use case below it works. The method increments the ndex before calling NextMethod, the usual extraction function. `[.zerobased` <- function(x, i, ...) { i <- i + 1L NextMethod() } as_zerobased <- function(x) { class(x) <- c("zerobased", class(x)) x } x <- 1:10 y <- as_zerobased(x) y[0] #> [1] 1 y[1] #> [1] 2 y[9] #> [1] 10 y[10] #> [1] NA Hope this helps, Rui Barrada...
2007 Sep 16
1
programming question
...0 In the first iteration, the first element 2 eliminates 8 and 26 because both contain number 2 in the last position (first line being shorter). The element 24 eliminates 51 and 78, and so on. `findSubsets2` <- function(element) { require(QCA) base3row <- getRow(rep(3,5), element, zerobased=TRUE) increment <- function(x, y) { a <- x for (i in 1:2) { a <- as.vector(outer(y, a, "+")) x <- c(x, a) } return(x) } indices <- which(base3row == 0) mbase <- c(81, 27, 9, 3, 1) for (i...
2024 Apr 21
5
x[0]: Can '0' be made an allowed index in R?
As we all know, in R indices for vectors start with 1, i.e, x[0] is not a correct expression. Some algorithms, e.g. in graph theory or combinatorics, are much easier to formulate and code if 0 is an allowed index pointing to the first element of the vector. Some programming languages, for instance Julia (where the index for normal vectors also starts with 1), provide libraries/packages that allow