[R] Converting 3 columns of a data frame into a matrix

David Winsemius dwinsemius at comcast.net
Tue Jun 22 16:53:06 CEST 2010


On Jun 22, 2010, at 4:57 AM, Jeff08 wrote:

>
> Okay, it crosstab seems to work when I clear out a bunch of my  
> variables,
> went from 800 mb Vcol to 100 mb
>
> Can anyone explain how memory works in R, because my lack of  
> understanding
> with memory was clearly the problem.

Making the assumption that you are on Windows, since you choose not to  
mention your OS. The Windows FAQ would be the first place to start:

http://cran.r-project.org/bin/windows/base/rw-FAQ.html

In particular:
http://cran.r-project.org/bin/windows/base/rw-FAQ.html#There-seems-to-be-a-limit-on-the-memory-it-uses_0021

There also many discussions in the archives. I use this function  
modified from some other person's code (but have forgotten the  
author)  to determine if I have memory allocation options. You could  
modify the function to display more than just the largest ten objects:

function() {z <- sapply(ls(envir=globalenv()),
                                 function(x) object.size(get(x)))
                (tmp <- as.matrix(rev(sort(z))[1:10]))}

  .... and then use rm() to delete the extraneous objects

-- 
David.
>
>
> Jeff08 wrote:
>>
>> ##I have also tried the reshape package
>> library(reshape)
>> mm  <- melt(df, id=c("date_", "id"))
>> mm1  <- cast(mm, date_~id)
>>
>> aba <- mm1[,-1]
>>
>> final <- as.matrix(aba)
>> colnames(final)  <-  df$id
>> rownames(final) <- mm1$date_
>> final
>>
>> ##Again it works perfectly here, but when I get to my real dataset,  
>> I get
>> a "Cannot allocate vector of size 27.4 MB" error
>>
>> It seems that the main problem is memory size. Is there an  
>> efficient way
>> to do this?
>>
>>

snipped what now appears to be tangential material

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list