通过给列索引替换数据表中的值 [英] Replace a value in a datatable by giving the column index
本文介绍了通过给列索引替换数据表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让 DT
成为此数据表:
DT <- data.table(A=1:2, B=3:4)
我们可以替换单元格在B列的第2行,像这样:
We can replace the cell at row 2 of column B like this:
DT[2, `:=`(B=99)]
但是我想通过提供列的 index 而不是名称来代替。
But I would like to replace by giving the index of the column, not its name. How?
推荐答案
您可以将数字索引作为第一个参数传递给:=
。例如
You can pass a numeric index as a first parameter to :=
. For example
DT[2, `:=`(2, 99)]
这篇关于通过给列索引替换数据表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文