[R] problem in finding sizes of objects using a for loop

Purna chander chanderbio at gmail.com
Thu Oct 25 08:24:11 CEST 2012


Dear All,

I wanted to extract the sizes of all created objects. For E.g when I
created 2 objects(x and y), I got their sizes using the following
code:

> x<-rnorm(10000)
> y<-runif(100,min=40,max=1000)
> ls()
[1] "x" "y"
> object.size(x)
80024 bytes
> object.size(y)
824 bytes

However, I was unable to get their sizes when I used a for loop in the
following way:

> objects<-ls()
> for (i in seq_along(objects)){
+   print(c(objects[i],object.size(objects[i])))
+
+ }
[1] "x"  "64"
[1] "y"  "64"


The result obtained by me is wrong in second case.

I understood that variables x and y are treated as characters. But to
rectify this problem.

Regards,
Purna



More information about the R-help mailing list