[R] resizing data

David Winsemius dwinsemius at comcast.net
Fri Jan 25 23:43:27 CET 2013


On Jan 25, 2013, at 2:29 PM, emorway wrote:

> I played around with your example on the smaller dataset, and it seemed like
> it was doing what I wanted.  However, applying it to the larger problem, I
> didn't  get a resized 2D dataset that preserved the order I was hoping for.
> Hopefully the following illustrates the larger problem:
> 
> x<-matrix(0,nrow=29328,ncol=7)
> 
> # Now set the 70,000th element to 1 to find out where it ends up?
> # Iterating on columns first, then rows, the 70,000th element is
> # at index [10000,7]

In an R matrix the "70,000"th element of a matrix with those dimensions would be in the 3rd column.

> 
> x[10000,7]<-1

That's not the 70000th element. its the (29328*6+1)th element. Given your  demonstrated misconceptions about R matrices and their column-major ordering I do not think I need to proceed further. Do some more self-study on R matrices.

> y<-t(matrix(x,nrow=546))
> dim(y)
> # [1] 376 546
> 
> # Does 1 appear at index [129,112] as I expect
> # (128 complete rows x 546 cols = 69888 + 112 = 70,000) thus, row 129, col
> 112
> y[129,112]
> # [1] 0
> 
> # No, so where is it? 
> grep(1,y)
> # [1] 123293
> 
> Where is that?
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/resizing-data-tp4656653p4656662.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.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list