add_index {fabR}R Documentation

Add an index column at the first place of a tibble

Description

Add an index, possibly by group, at the first place of a data frame or a tibble The name by default is 'index' but can be named. If 'index' already exists, or the given name, the column can be forced to be created, and replace the other one.

Usage

add_index(tbl, name_index = "index", start = 1, .force = FALSE)

Arguments

tbl

tibble or data frame

name_index

A character string of the name of the column.

start

integer indicating first index number. 1 by default.

.force

TRUE or FALSE, that parameter indicates whether or not the column is created if already exists. FALSE by default.

Value

A tibble or a data frame containing one extra first column 'index' or any given name.

Examples

{

##### Example 1 -------------------------------------------------------------
# add an index for the tibble
add_index(iris, "my_index")

##### Example 2 -------------------------------------------------------------
# add an index for the grouped tibble
library(tidyr)
library(dplyr)

my_tbl <- tibble(iris) %>% group_by(Species) %>% slice(1:3)
add_index(my_tbl, "my_index")

}


[Package fabR version 2.1.0 Index]