Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 环路中的子集ffdf_R_Ff_Ffbase - Fatal编程技术网

R 环路中的子集ffdf

R 环路中的子集ffdf,r,ff,ffbase,R,Ff,Ffbase,我正在尝试使用ffbase在循环中子集一个非常大的ffdf对象,但是我得到了错误消息: Error in UseMethod("as.hi") : no applicable method for 'as.hi' applied to an object of class "NULL" 我在ssh上运行这段代码,并且有大量可用内存。下面是我试图运行的代码: # totalD is an ffdf with columns ID, TS, and TD, each with 288,133,58

我正在尝试使用ffbase在循环中子集一个非常大的ffdf对象,但是我得到了错误消息:

Error in UseMethod("as.hi") : no applicable method for 'as.hi' applied to an object of
class "NULL"
我在ssh上运行这段代码,并且有大量可用内存。下面是我试图运行的代码:

# totalD is an ffdf with columns ID, TS, and TD, each with 288,133,589 rows. ID consists
# of integers. TS is a column of integer timestamps with second precision. TD is of type
# double. Uid3 is an integer vector consisting of the 1205 unique entries of totalD$ID.

# H_times creates a matrix of the sum of the entries in TD traveled in each hour
H_times <- function(totalD, Uid3) {

    # hours is the number of unique hours of the experiment
    hours <- length(unique(subset(totalD$TS, totalD$TS %% 3600 == 0)))-1

    # bH is used as a counter in a the following loops
    bH <- min(unique(subset(totalD$TS, totalD$TS %% 3600 == 0)))

    # sum_D_matrix is the output
    sum_D_matrix <- matrix(0, nrow = hours, ncol = length(Uid3))

    for(i in 1:length(Uid3)) {
        Bh <- bH
        for(j in 1:hours) {
            sum_D_matrix[j,i] <- sum(subset(totalD$TD, totalD$TS >= Bh & totalD$TS < (Bh + 3600) & totalD$ID == Uid3[i]))
            Bh <- Bh + 3600
        }
    }
    save(sum_D_matrix, file = "sum_D_matrix)
}

H_times(totalD, Uid3)

我试图实现jwijffels在问题评论中建议的修复,但没有效果。提前谢谢

这是由线路引起的:

sum_D_matrix[j,i] <- sum(subset(totalD$TD, 
    totalD$TS >= Bh & totalD$TS < (Bh + 3600) & totalD$ID == Uid3[i]))
当生成的向量为空时,FFT返回NULL,正如我提到的,它不能返回长度为0的向量

旁注

您使用子集的方式实际上有点奇怪。使用子集的原因之一是通过去掉所有的totalD$来简化表示法。更“常用”的使用方式是:

sum_D_matrix[j,i] <- sum(subset(totalD, TS >= Bh & TS < (Bh + 3600) & ID == Uid3[i], 
    TD, drop=TRUE))

谢谢当我使用你的代码和它的变体时,我得到了一个错误,其中“which”的chevale,nl,envir:argument是不符合逻辑的。
sum_D_matrix[j,i] <- sum(subset(totalD, TS >= Bh & TS < (Bh + 3600) & ID == Uid3[i], 
    TD, drop=TRUE))