Generate Row number to the dataframe in R

To Generate Row number to the dataframe in R we will be using seq.int() function.  Seq.int() function along with nrow() is used to generate row number to the dataframe in R.

Let’s first create the dataframe

df1 = data.frame(State = c('Arizona AZ','Georgia GG', 'Newyork NY','Indiana IN','Florida FL'), Score=c(62.345,47.734,55.867,74.256,31.901))
df1

Generate row number of dataframe in R 1

 

Generate Row number to the dataframe:

Row number is generated and stored in a column

df1$row_num <- seq.int(nrow(df1))
df1

so the resultant dataframe will be

Generate row number of dataframe in R 2