[Solved] How to add column in a data frame with values based on the length of data as as string [duplicate]


We can use paste

iris$Observation <- paste0("Obs_", seq_len(nrow(iris)))

If we are using tidyverse, there is row_number() function

library(dplyr)
iris %>%
     mutate(Observation = paste0("Obs_", row_number()))

solved How to add column in a data frame with values based on the length of data as as string [duplicate]