Alternative to expand.grid for data.frames

前端 未结 6 1465
误落风尘
误落风尘 2020-11-27 16:22

I have a data.frame df and I want that every row in this df is duplicated lengthTime times and that a new column is added that counts

6条回答
  •  独厮守ぢ
    2020-11-27 17:01

    Why not just something like df[rep(1:nrow(df),times = 3),] to extend the data frame, and then add the extra column just as you have above, with df$Time <- rep(1:lengthTime, each=nrRow)?

提交回复
热议问题