search for: as_zerobased

Displaying 2 results from an estimated 2 matches for "as_zerobased".

2024 Apr 21
1
x[0]: Can '0' be made an allowed index in R?
...ing 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 Barradas -- Este e-mail foi analisado pelo software antiv?rus AVG para verificar a...
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