我正在寻找一种简单的方法来替换data.frame中的行
dados <- data.frame(a = c("A", "B", "C"), b = c(1,2,3))
new_record <- data.frame(a = "G", b = 99)
# replace row
dados[2, ] <- new_record[1, ]
这不起作用。什么是最简单的方法?
答案 0 :(得分:2)
如果您希望/ {必须将列<div ng-controller="MyCtrl">
<div ng-repeat="line in parent">
<div class="header">{{line.name}}</div>
<table>
<tr>
<td ng-repeat="satellites in line.satellites">{{satellites.name}}
<div>{{satellites.image}}</div>
</td>
</tr>
<tr>
<td ng-repeat="continents in line.continents">{{continents.name}}
<div>{{continents.image}}</div>
</td>
<tr/>
</table>
<div class="header">Population</div>
<div>{{line.population.graph}}</div>
</div>
</div>
保持为a
,您可以先调整因子级别,然后创建新的数据集:
factor
答案 1 :(得分:1)
Andriy是正确的,在创建data.frame时使用stringsAsFactors = FALSE
。否则,生成的因子级别在两个data.frames之间将不匹配,您将看到此警告:
Warning message:
In `[<-.factor`(`*tmp*`, iseq, value = 1L) :
invalid factor level, NA generated