Alternative to expand.grid for data.frames

前端 未结 6 1466
误落风尘
误落风尘 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 16:56

    This works:

    REP <- rep(1:nrow(df), 3)
    df2 <- data.frame(df[REP, ], Time = rep(1:3, each = 9))
    rownames(df2) <- NULL
    df2
    

提交回复
热议问题