Select Page

How to Add an Index column to a Data Frame in R

The easiest way to add a sequence of numbers as an index column is to use the nrow() function, for example, df$index <- 1:nrow(df) This tutorial will explain how to add a numeric ID column to a data frame with code examples. Table of contentsAdd Index Column to...