添加行至数据框
问题:
有时需要给数据框添加一行或者更多新行
结局方案:
创建第二个包含这些新行的临时数据框,然后调用rbind()函数将这个临时数据框添加到原始数据框后面:
> b
city country state pop
1 Chicago Cook IL 2853144
2 Kenosha Kenosha WI 90352
3 Aurora Kane IL 171782
4 Elgin Lake IL 94487
> newRow<-data.frame(city="Cicero",country="Cook",state="IL",pop=72616)
> newb<-rbind(b,newRow)
> newb
city country state pop
1 Chicago Cook IL 2853144
2 Kenosha Kenosha WI 90352
3 Aurora Kane IL 171782
4 Elgin Lake IL 94487
5 Cicero Cook IL