[R] Fw: efficiently replacing values in a matrix

From: Nnamdi <nnamdii_at_yahoo.com>
Date: Fri, 18 Apr 2008 11:17:06 -0700 (PDT)

I tried the sparse matrix implementation, still there are issues:

a <- matrix(nrow=10000,ncol=10000)
> a.csr <- as.matrix.csr(a)

Error in if (nnz == 0) { : missing value where TRUE/FALSE needed

I'm guessing this error here is because 'a' matrix is initialized with'NA's. Yet when I try initializing 'a' matrix with 0s I get:
> a<-matrix(nrow=10000,ncol=10000,rep(0,10000*10000))
Error: cannot allocate vector of size 762.9 Mb

Either way I cannot achieve my goal of being able to efficiently enter values into this matrix.

To answer your previous question, this matrix is somewhat dense. It is a symmetrical matrix thus only the upper triangle is filled.

Any other ideas? Thanks again

--Nnamdi

is this really a dense matrix? if not, then sparse representations would be much more efficient...

url:    www.econ.uiuc.edu/~roger            Roger Koenker
email    rkoenker_at_uiuc.edu            Department of Economics
vox:     217-333-4558                University of Illinois
fax:       217-244-6678                Champaign, IL 61820


On Apr 18, 2008, at 12:11 PM, Nnamdi wrote:

>
> Still it is pretty slow when entering values into a large matrix.
> Case in
> point:
>
>> a <- matrix(nrow=10000,ncol=10000)
>> system.time(a[1,1] <- 1903908.80385)
> user system elapsed
> 30.840 6.226 41.416
>> is.matrix(a)
> [1] TRUE
>
> Is there a better way to enter values into large matrices? If I have
> to
> spend 41 secs each time I enter into a cell and I have 10000x10000
> cells to
> enter that is impractical!
>
> --Nnamdi
>
> Rolf Turner-3 wrote:
>>
>>
>> On 17/04/2008, at 9:33 AM, Charles C. Berry wrote:
>>
>> <snip>
>>
>>> I'll lay odds that Matthew's 'matrix' is actually a data.frame, and
>>> I'll not be surprised if the columns are factors.
>>
>> <snip>
>>
>> I suspect that you're right.
>>
>> ***Why*** can't people distinguish between data frames and matrices?
>> If they were the same <expletive deleted> thing, there wouldn't be
>> two
>> different terms for them, would there?
>>
>> cheers,
>>
>> Rolf Turner
>>
>> ######################################################################
>> Attention:\ This e-mail message is privileged and confid...
>> {{dropped:9}}
>>
>> ______________________________________________
>> 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.
>>
>>
>
> --
> View this message in context: http://www.nabble.com/efficiently-replacing-values-in-a-matrix-tp16732795p16763578.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



Be a better friend, newshound, and

Be a better friend, newshound, and

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. Received on Fri 18 Apr 2008 - 19:10:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 18 Apr 2008 - 20:30:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive