[問題] for迴圈問題
[問題類型]:
程式諮詢(我想用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.
有點不解, 想一日了自己解決不出來想請教可以怎麼改善
謝謝回復
[程式範例]:
[關鍵字]:
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.234.34
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1527689340.A.342.html
→
05/30 23:56, 
                                7年前
                            , 1F
05/30 23:56, 1F
→
05/30 23:57, 
                                7年前
                            , 2F
05/30 23:57, 2F
→
05/31 00:01, 
                                7年前
                            , 3F
05/31 00:01, 3F
→
05/31 00:05, 
                                7年前
                            , 4F
05/31 00:05, 4F
→
05/31 09:16, 
                                7年前
                            , 5F
05/31 09:16, 5F
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章