1

以下に示す R コードの一部は、1 つのフォルダー内の多くのファイル (12) の計算を実行するためのものです。しかし、私はこのエラーが発生しています:

エラー: 添え字が範囲外です。

最初のファイルの読み込みは終了しましたが、次のファイルの読み込みを開始したときにエラーが発生しました。なぜ何か提案はありますか?

library(Matrix)
setwd("C:\\Users\\Desktop\\img")
listfile <- dir()
long <- file("C:\\Users\\Desktop\\New folder (5)\\vfd.bin", "rb")
A = readBin(long, integer(), size=2,n=67420*1, signed=F)
ta <- t(A)
lot <- file("C:\\Users\\Desktop\\New folder (5)\\lat.img", "rb")
B = readBin(lot, integer(), size=2,n=67420*1, signed=F)
tb <-t (B)

for (n in 1:length(listfile))
{
    h = listfile[n]
    b = file.info(h[n])$size/67420/4
    wind <- file(h, "rb")
    C = readBin(wind, double(), size=4,n=67420*b, signed=TRUE)
    D <- matrix(C,nrow=b,ncol=67420)
    for(d in 1:b)
    {
        M <- Matrix(-9999, 360, 720)
        tm <- t(M)
        for(i in 1:67420)
        {
            tm[ta[i],tb[i]] = round(10 * ((D[(d-1)*8+1,i] + D[(d-1)*8+2,i] + D[(d-1)*8+3,i] + D[(d-1)*8+4,i] + D[(d-1)*8+5,i] + D[(d-1)*8+6,i] + D[(d-1)*8+7,i] + D[(d-1)*8+8,i] ) / 8))
        } ###gooooooood
        to.write <- sprintf("C:\\Users\\Desktop\\New folder (6)\\Yar_%00d.bin", d)
        writeBin(as.integer(tm@x), size=2,to.write)
    }
}
4

1 に答える 1