Alternative to expand.grid for data.frames

前端 未结 6 1468
误落风尘
误落风尘 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:04

    Quick update

    There is now also the crossing() function in package tidyr which can be used instead of merge, is somewhat faster, and returns a tbl_df / tibble.

    data.frame(time=1:10) %>% merge(iris, by=NULL) 
    
    data.frame(time=1:10) %>% tidyr::crossing(iris) 
    

提交回复
热议问题