[R] rownames cannot allocate vector of size

Benilton Carvalho beniltoncarvalho at gmail.com
Mon Feb 22 11:02:21 CET 2010


assigning rownames (after the object is created) triggers a copy of
the object... if you assign the rownames at creation time, no extra
copies...

b

On Mon, Feb 22, 2010 at 9:46 AM, Larson, TR <trl1 at york.ac.uk> wrote:
> Hi,
>
> On R 2.10.1 for Windows, when I do the following to duplicate the structure
> of a large numeric matrix called matrix1:
>
> matrix2 <- matrix(0,nrow=nrow(matrix1),ncol=ncol(matrix1))
>
> and then
>
> rownames(matrix2) <- rownames(matrix1)
>
> I get a "cannot allocate vector of size xxMb" error
>
> but if I instead do:
>
> rnames <- list()
> rnames <- rownames(matrix1)
> matrix2 <- matrix(0,nrow=nrow(matrix1),ncol=ncol(matrix1),dimnames=rnames)
>
> I get no error.
>
> Of course both approaches work in R on Unix without memory limits.  But I'm
> intrigued about the apaprent difference in memory usage/allocation for the
> two above approaches. Is there any explanation for this difference in
> behaviour?
>
> thanks
> Tony
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list