Skip to main content

Timeline for answer to Extract Matrix of Values from Matrix using Matrix of Row Numbers by Nadir AMMISAID

Current License: CC BY-SA 4.0

Post Revisions

9 events
when toggle format what by license comment
Apr 10 at 8:38 comment added Nadir AMMISAID @Greg Thanks Greg. Agreed ! dim<- is the idiomatic solution here. At the R level, [ returns a vector, so there's no special extraction form that preserves the shape directly; whether resetting dim happens truly in place depends on copy-on-modify semantics.
Apr 10 at 8:37 history edited Nadir AMMISAID CC BY-SA 4.0
Clarified why dim<- is the idiomatic solution and added note about copy-on-modify semantics
Apr 9 at 18:30 comment added Rui Barradas Another one-liner is 'dim<-'(vals[val_rows, val_col], dim(val_rows)). (With back quotes.)
Apr 9 at 16:28 comment added Greg Hello Nadir, and welcome! You are right that byrow = TRUE is inappropriate, and that helped me realize that my `dim<-`() approach was correct all along. I simply "had my wires crossed" regarding my output. I have updated my post with clearer output and questions.
Apr 9 at 16:17 comment added Greg @G Don't array() and structure() both pass by value? I'm hoping that something exists which is (1) similar to `dim<-`() and (2) can redimension "in place", without copying the underlying data.
Apr 9 at 16:11 comment added G. Grothendieck You might want to use array instead of structure.
Apr 9 at 15:43 vote accept Greg
Apr 9 at 16:03
S Apr 9 at 15:20 review First answers
Apr 9 at 15:26
S Apr 9 at 15:20 history answered Nadir AMMISAID CC BY-SA 4.0