How to insert a bookmark that grows numerically in a dataframe in R?

0

I have a dataframe with a column and a certain number of rows that varies. What I'm working on are 17. In each line there is a different expression, more or less similar to "ID 123456, color = blue".

I would like to add to each of the lines a word that helps me identify each of these lines. I would need something of the type cod1, cod2, cod3 etc. It turns out that as I said before, the amount of lines changes regularly. So in this case there are 17 lines, but they can be more or less. Therefore, you would need the word that identifies each of these lines to fit the number of lines.

    
asked by anonymous 08.05.2017 / 23:48

1 answer

0

Hello,

You can do one like this:

for(j in 1:dim(seu dataframe)[1]){
    seu dataframe[j,]$posicao <- paste0("cod",j)
    j=j+1
  }

This function will concatenate the word cod with the counter ... it will be cod1 in the first line, cod2 in the second and so on.

    
11.05.2017 / 20:47