Create a variable that identifies the original data.frame after rbind command in R

后端 未结 6 591
后悔当初
后悔当初 2020-12-11 06:07

I am relatively new to R and I would like to know how can I create a variable (number sequence) that identifies the each of the original data.frames before being joined with

6条回答
  •  萌比男神i
    2020-12-11 06:33

    You can use

    transform(dat, newCol = cumsum(ID == 1))
    

    where dat is the name of your data frame and ID is the name of the ID column.

提交回复
热议问题