-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
74 lines (54 loc) · 1.64 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# index0: Zero-based Indexing in R
<!-- badges: start -->
[![R-CMD-check](https://github.com/Selbosh/index0/workflows/R-CMD-check/badge.svg)](https://github.com/Selbosh/index0/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/index0)](https://CRAN.R-project.org/package=index0)
<!-- badges: end -->
The R programming language uses indices that start from 1, but sometimes it
might be handy to be able to index from zero, as is more typical in mathematical
notation and some other programming languages like C and Python.
## Installation
Install the **index0** package from CRAN using:
```r
install.packages('index0')
```
Or you can get the latest development version from GitHub with:
``` r
# install.packages("remotes")
remotes::install_github("Selbosh/index0")
```
## Usage
This R package **index0** provides the `index0` class.
Subsetting and operations using `[` will index from zero rather than one.
To return to normal behaviour, use `as.index1` or just remove the `index0` class
from your object.
```{r example}
library(index0)
letters0 <- as.index0(letters)
numbers0 <- as.index0(c(2, 3, 4, 5, 6))
```
What is the zeroth letter of the alphabet? What is the zeroth number in our set?
```{r}
letters0[0]
numbers0[0]
```
What are the first, second and fourth letters?
```{r}
letters0[c(1, 2, 4)]
```
Replace the first and third numbers with `NA`:
```{r}
numbers0[c(1, 3)] <- NA
numbers0
```