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

后端 未结 6 611
后悔当初
后悔当初 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条回答
  •  一个人的身影
    2020-12-11 06:32

    Why not just:

        rbind( cbind(df1, origin="df1"),
               cbind(df2,  origin='df2') )
    

    Or if you want to preserve rownames:

      rbind( cbind(df1, origin=paste("df1",rownames(df1), sep="_") ),
             cbind(df2, origin=paste("df1",rownames(df1), sep="_") ) )
    

提交回复
热议问题