[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
入門(寫過其他程式,只是對語法不熟悉)
[問題敘述]:
for(j in 1:nrow(datasteel))
if (datasteel[j,28]==1)
{
datasteel[j,35] <- colnames(datasteel[,28])
}
for(j in 1:nrow(datasteel))
if (datasteel[j,29]==1)
{
datasteel[j,35] <- colnames(datasteel[,29])
}
for(j in 1:nrow(datasteel))
if (datasteel[j,30]==1)
{
datasteel[j,35] <- colnames(datasteel[,30])
}
....
for(j in 1:nrow(datasteel))
if (datasteel[j,34]==1)
{
datasteel[j,35] <- colnames(datasteel[,34])
}
我寫成這樣
for(i in 28:34)
{
for(j in 1:nrow(datasteel)){
if (datasteel[j,i]==1)
{
datasteel[j,35] <- colnames(datasteel[,i])
}}
}
Error in `[.data.table`(datasteel, j, i) :
j (the 2nd argument inside [...]) is a single symbol but column name 'i' is
not found. Perhaps you intended DT[, ..i]. This difference to data.frame is
deliberate and explained in FAQ 1.1.
有點不解, 想一日了自己解決不出來想請教可以怎麼改善
謝謝回復
[程式範例]:
[關鍵字]: