【发布时间】:2022-07-14 21:41:53
【问题描述】:
我有一个包含以下列的数据框:
tester <- data.frame(id = c(123456789, 987654321))
tester$furniture <- list(c("chair"), c("bed", "bench", "barstool"))
tester$count <- c(1,3)
根据count列的值,每行重复[count]次:
tester[rep(seq_len(dim(tester_2)[1]), tester$count),]
家具清单中的物品数量将始终等于计数值
我想创建一个新列,其中包含列表中的一个项目,按从第一个到最后一个列表项的顺序排列。我会在这个新列中手动输入我想要的内容:
tester$new <- c("chair", "bench", "bed", "barstool"),但这现在不起作用,因为从上面的代码产生的数据帧在技术上只有两行。
任何建议将不胜感激!
【问题讨论】:
标签: r string dataframe duplicates