Code Monkey home page Code Monkey logo

index0's Introduction

index0: Zero-based Indexing in R

R-CMD-check CRAN status

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:

install.packages('index0')

Or you can get the latest development version from GitHub with:

# 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.

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?

letters0[0]
#> [0] "a"
#> indexed from 0
numbers0[0]
#> [0] 2
#> indexed from 0

What are the first, second and fourth letters?

letters0[c(1, 2, 4)]
#> [0] "b" "c" "e"
#> indexed from 0

Replace the first and third numbers with NA:

numbers0[c(1, 3)] <- NA
numbers0
#> [0]  2 NA  4 NA  6
#> indexed from 0

index0's People

Contributors

selbosh avatar

Stargazers

 avatar Nick O'Brien avatar Srikanth K S avatar Mark Keller avatar Richard McElreath avatar  avatar JohannesFriedrich avatar Andrew Gerst avatar Sonia Mitchell avatar M. Amalan avatar Matt Dray avatar Michael Sumner avatar Adam H. Sparks avatar Martin Stein avatar Serdar Balcı avatar Deblina Mukherjee avatar Emil Hvitfeldt avatar boB Rudis avatar

Watchers

James Cloos avatar  avatar

index0's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.