假设我有一个数据集,随着时间的推移,行不断脱落,我想再次添加这些行。
缺少行的示例:
Fruits <- c(rep(c("apples","oranges","pears","kiwis"),3),
"bananas","oranges","pears","kiwis","bananas","pears","kiwis","bananas")
Days <- c(rep("Monday",4),rep("Tuesday",4),rep("Wednesday",5),
rep("Thursday",4),rep("Friday",3))
Amounts <- c(10,15,20,20,10,15,20,20,10,15,20,20,25,15,20,20,25,20,20,25)
dfmissing <- data.frame(Fruits,Days,Amounts)
我希望它在周四和周五“苹果”和“橙子”这样退出时填补新的行。
请注意,“香蕉”在星期三首次出现,这使事情变得有些复杂。
完成的表格应如下所示
Fruits <- c(rep(c("apples","oranges","pears","kiwis"),2),
rep(c("apples","oranges","pears","kiwis","bananas"),3))
Days <- c(rep("Monday",4),rep("Tuesday",4),
rep("Wednesday",5),rep("Thursday",5),rep("Friday",5))
Amounts <- c(rep(c("10","15","20","20"),2),rep(c("10","15","20","20","25"),3))
dfcomplete <- data.frame(Fruits,Days,Amounts)
比较两张表
dfmissing
dfcomplete
假设只有一周的数据,因此“星期一”永远不会重复等 - “天”列是独特因素的列表。
提前致谢。