Re: [Rcpp-devel] Splitting a matrix by its rows into a list

2013-02-19 Thread Søren Højsgaard
-devel] Splitting a matrix by its rows into a list There is a sleazy hack which works, but wastes a fair amount of memory: take the transpose of the matrix in R, and use the fact that the columns of that transpose are the rows of the original. On Mon, Feb 18, 2013 at 5:37 PM, Dirk Eddelbuettel

Re: [Rcpp-devel] Splitting a matrix by its rows into a list

2013-02-19 Thread Romain Francois
This was a bug, and is fixed in rev 4262. Romain Le 19/02/13 00:37, Søren Højsgaard a écrit : I want to split a matrix by its rows into a list as: a<- matrix(letters[1:6],ncol=2) split(a,row(a)) $`1` [1] "a" "d" $`2` [1] "b" "e" $`3` [1] "c" "f" I do as follows and get a strange result. An

Re: [Rcpp-devel] Splitting a matrix by its rows into a list

2013-02-18 Thread John Merrill
There is a sleazy hack which works, but wastes a fair amount of memory: take the transpose of the matrix in R, and use the fact that the columns of that transpose are the rows of the original. On Mon, Feb 18, 2013 at 5:37 PM, Dirk Eddelbuettel wrote: > > On 18 February 2013 at 17:02, Kevin Ushe

Re: [Rcpp-devel] Splitting a matrix by its rows into a list

2013-02-18 Thread Dirk Eddelbuettel
On 18 February 2013 at 17:02, Kevin Ushey wrote: | One solution: X.row(ii) is actually generating a CharacterMatrix::Row ; ie, a | view of that row in the CharacterMatrix, and I think you need to explicitly | copy it to a CharacterVector and then assign that CharacterVector to the list. | | You c

Re: [Rcpp-devel] Splitting a matrix by its rows into a list

2013-02-18 Thread Kevin Ushey
One solution: X.row(ii) is actually generating a CharacterMatrix::Row ; ie, a view of that row in the CharacterMatrix, and I think you need to explicitly copy it to a CharacterVector and then assign that CharacterVector to the list. You could write something like: src <- ' CharacterMatrix X(XX_

[Rcpp-devel] Splitting a matrix by its rows into a list

2013-02-18 Thread Søren Højsgaard
I want to split a matrix by its rows into a list as: > a<- matrix(letters[1:6],ncol=2) > split(a,row(a)) $`1` [1] "a" "d" $`2` [1] "b" "e" $`3` [1] "c" "f" I do as follows and get a strange result. Any suggestions? Thanks in advance! Søren --- src <- ' CharacterMatrix X(XX_);