Re: [R] How to insert a vector or matrix into an existing matrix

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Mon, 21 Apr 2008 12:50:08 +0000 (UTC)

Gabor Csardi <csardi_at_rmki.kfki.hu> wrote in news:20080421071002.GA16849_at_localdomain:

> On Sun, Apr 20, 2008 at 08:16:11PM +0000, David Winsemius wrote:

>> Gabor Csardi <csardi@rmki.kfki.hu> wrote in
>> news:20080420133926.GA28167_at_localdomain:
>>
>> > Hmm, my understanding is different,
>> >
>> > m <- matrix(sample(10*10), ncol=10)
>> > m2 <- rbind( m[1:5,], 1:10, m[6:10,] )
>> > m3 <- cbind( m[,1:8], 1:10, m[,9:10] )
>>
>> I read the question the same way and, in response to the part of
>> the question asking for no temporary matrix, offer this refinement
>> on your suggestion:
>>
>> m <- rbind( m[1:5,], 1:10, m[6:10,] ) # row insertion or ...
>>
>> # not to be followed by, but rather instead column insertion ..
>> m <- cbind( m[,1:8], 1:10, m[,9:10] )
> 
> There might be something wrong with my eyes, but where is the
> refinement here? Your lines are literally the same as mines. There
> is no temporary matrix here, m2 and m3 are the results, he wanted
> either between row 5 and 6 _OR_ column 8 and 9. 
> 
> Oh, if you mean that we immediately put back the result into 'm',
> then 1) it does not really matter, R will create a temporary matrix 
> internally anyway, 

Am I correct in assuming that after the creation of m by way of a temporary matrix that the temporary matrix would then be available for garbage collection, whereas if both m and m2 were created, there would be more memory occupied by the two objects?

-- 
David Winsemius

______________________________________________
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 Mon 21 Apr 2008 - 12:59:24 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 Mon 21 Apr 2008 - 13:30:32 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