我試圖在R只是添加一個簡單的常數到表中的列與例如R列表/表操作替換「for」循環與sapply?
dim(exampletable)
[1] 3900 2
增加值在第二列中,我所做的事情和工作原理是:
newtable <- exampletable
for (i in 1:nrow(newtable)){newtable[i,2] <- exampletable[i,2] + constant}
但這似乎有點矯枉過正。有沒有更好的方法可以做到這一點,比如sapply?
謝謝,約翰內斯
是的! 'newtable [,2] < - newtable [,2] +常量' –