index_func: Count the occurence of a value in a vector.

View source: R/index_func.R

index_funcR Documentation

Count the occurence of a value in a vector.

Description

For when you want to know which occurence a value is in a vector and not just the number of times that it was duplicated.

Usage

index_func(a)

Arguments

a

A vector or column in a data frame

Value

A vector of counts that increase with each appearance of a value in a vector.

Examples

library(dplyr)
library(tibble)

foo <- tibble::tribble(
  ~numbers, ~numbers2,
        4L,        4L,
       23L,       23L,
        4L,        4L,
       23L,       23L,
        5L,        5L,
       43L,       43L,
       54L,       54L,
       56L,       56L,
      657L,      657L,
       67L,       67L,
       67L,       67L,
      435L,      435L,
      453L,      453L,
      435L,      435L,
      324L,      324L,
       34L,       34L,
      456L,      456L,
       56L,       56L,
      567L,      567L,
       65L,       65L,
       34L,       34L,
      435L,      435L
  )

foo %>%
  mutate(index = index_func(numbers))

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.