我有一個基本的 while 和 for 回圈,我遍歷資料框中的一些起始值和結束值,然后遍歷一個串列并獲取(子字串)一些值。
下面代碼的問題是它添加了很多 NA 行,我不明白為什么以及如何。
我有一個查看 GREPL 的 if 找到“TRACK 2 DATA:”,如果是,則在資料框中添加一行。我沒有添加 NA 值的 else 。所以在我的理解中,如果 Block 為假,迭代應該繼續而不是向資料框添加值?
可能有什么問題?
i=1
fundi <- nrow(find_txn) #get the last record
while(i <=fundi) { # Start while-loop until END OF records
nga <- find_txn[i,1] #FRom record
ne <- find_txn[i,3] #to Records
for (j in nga:ne){ #For J in from:to
if(grepl("TRACK 2 DATA: ",linn[j])) { #If track data found do something
gather_txn[j,1] <- j # add a record for iteration number
gather_txn[j,2] <- substr(linn[j],1,9) #get some substrings
gather_txn[j,3] <- substr(linn[j],34,39) #get some substrings
}
}
i <- i 1
}
uj5u.com熱心網友回復:
我在回圈錯誤的變數。內部 if 回圈需要使用i而不是j變數添加到表中:
gather_txn[i,1] <- j # add a record for iteration number
gather_txn[i,2] <- substr(linn[j],1,9) #get some substrings
gather_txn[i,3] <- substr(linn[j],34,39) #get some substrings
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/411462.html
標籤:
上一篇:用python模擬足球聯賽
下一篇:如何遍歷二進制數字的嵌套串列并將其十進制數字附加到串列中?例如:[[0,0,1,0,1],[1,0,0,0,1]]==[5,17]
