Adding a column with consecutive numbers in R

后端 未结 3 1528
不思量自难忘°
不思量自难忘° 2021-02-13 14:14

I apologize if this question is abhorrently simple, but I\'m looking for a way to just add a column of consecutive integers to a data frame (if my data frame has 200 observation

3条回答
  •  日久生厌
    2021-02-13 14:58

    Or use dplyr.

    library(dplyr)
    df %>% mutate(observation = 1:n())
    

    You might want it to be the first column of df.

    df %>% mutate(observation = 1:n()) %>% select(observation, everything())
    

提交回复
热议问题