简体   繁体   中英

What is the difference between “Large Matrix” and regular numeric matrix?

When a relatively large matrix is created, Rstudio marks it as a Large Matrix in its environment window:

 x <- matrix(rnorm(10000 * 5000), ncol=5000)
 # Large matrix (50000000 elements, 381.5 Mb)

The mode() function as expected returns "numeric" for this object:

mode(x)
## [1] "numeric"

If however I run the following command:

mode(x) <- "numeric"

Rstudio changes "Large Matrix" into a regular numeric matrix:

# x:  num [1:10000, 1:5000]

So what is the difference between these 2 objects? Does this difference exist in Rstudio only or these two objects are different in R as well?

In my understanding, "Large Matrix" and matrix is the same matrix object. What matters is how these objects are displayed in the global environment in RStudio.

RStudio also distinguishes between vectors and large vectors. Consider the following vector:

n <- 256
v1 <- rnorm(n*n-5)

This vector is listed as a large vector. Now, let's decrease its size by one:

v2 <- rnorm(n*n-6)

Suddenly, it becomes a normal vector. The structure of both objects is the same (which can be verified by running str ). So is their class and storage mode. What is different then? Notice that the size of v2 in memory is exactly 512 Kb.

lobstr::obj_size(v2)
>524,288 B # or exactly 512 kB

The size of v1 is slightly greater:

lobstr::obj_size(v1)
>524,296 B # or 512.0078125 KB

As far as I understand (correct me if I am wrong), for mere convenience RStudio displays objects that are greater than 512 kB differently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM