Large Matrices in R: long vectors not supported yet

前端 未结 3 2291
Happy的楠姐
Happy的楠姐 2020-12-06 00:53

I am running 64 bit R 3.1 in a 64bit Ubuntu environment with 400GB of RAM, and I am encountering a strange limitation when dealing with large matrices.

I have a num

3条回答
  •  感动是毒
    2020-12-06 01:03

    A matrix is just an atomic vector with a dimension attribute which allows R to access it as a matrix. Your matrix is a vector of length 4000*9000000 which is 3.6e+10 elements (the largest integer value is approx 2.147e+9). Subsetting a long vector is supported for atomic vectors (i.e. accessing elements beyond the 2.147e+9 limit). Just treat your matrix as a long vector.

    If we remember that by default R fills matrices column-wise then if we wanted to retrieve say the value at test[ 2701 , 850000 ] we could access it via:

    i <- ( 2701 - 1 ) * 850000 + 2701 
    test[i]
    #[1] 1
    

    Note that this really is long vector subsetting because:

    2701L * 850000L
    #[1] NA
    #Warning message:
    #In 2701L * 850000L : NAs produced by integer overflow
    

提交回复
热议问题