On Dec 29, 2013, at 7:21 PM, Gregory Carey wrote:
> Please see the code and R output below. I cannot understand why a
> matrix object is being propagated in row major order by default and
> then in column major order when byrow=TRUE is specified when I use
> one set of dimensions. But when I use different dimensions, the
> propagation is correct.
You appear to be reversing the terms column-major and row-major order
from the fashion in which they are being used by the majority of
commenters in R help. The first example without byrow=TRUE is what I
would have called column-major while the second is row-major.
The third example appears to be loading values in column-major order.
So I do not see any inconsistency.
--
David.> Greg
>
>> pvec <- colMeans(rbind(hapn, hapn2))
>> class(pvec)
> [1] "numeric"
>> length(pvec)
> [1] 100
>> pvec[1:5]
> [1] 0.08263811 0.59034639 0.21173734 0.77819000 0.11360578
>> nLoci
> [1] 100
>> nObs
> [1] 500
>> pvecMat <- matrix(pvec, nLoci, nObs)
>> pvecMat[1:5, 1:7]
> [,1] [,2] [,3] [,4] [,5] [,
> 6] [,7]
> [1,] 0.08263811 0.08263811 0.08263811 0.08263811 0.08263811
> 0.08263811 0.08263811
> [2,] 0.59034639 0.59034639 0.59034639 0.59034639 0.59034639
> 0.59034639 0.59034639
> [3,] 0.21173734 0.21173734 0.21173734 0.21173734 0.21173734
> 0.21173734 0.21173734
> [4,] 0.77819000 0.77819000 0.77819000 0.77819000 0.77819000
> 0.77819000 0.77819000
> [5,] 0.11360578 0.11360578 0.11360578 0.11360578 0.11360578
> 0.11360578 0.11360578
>> pvecMat2 <- matrix(pvec, nLoci, nObs, byrow=TRUE)
>> pvecMat2[1:5, 1:7]
> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> [1,] 0.08263811 0.5903464 0.2117373 0.77819 0.1136058 0.149802
> 0.829995
> [2,] 0.08263811 0.5903464 0.2117373 0.77819 0.1136058 0.149802
> 0.829995
> [3,] 0.08263811 0.5903464 0.2117373 0.77819 0.1136058 0.149802
> 0.829995
> [4,] 0.08263811 0.5903464 0.2117373 0.77819 0.1136058 0.149802
> 0.829995
> [5,] 0.08263811 0.5903464 0.2117373 0.77819 0.1136058 0.149802
> 0.829995
>> matrix(pvec, 2, 5)
> [,1] [,2] [,3] [,4] [,5]
> [1,] 0.08263811 0.2117373 0.1136058 0.8299950 0.7709431
> [2,] 0.59034639 0.7781900 0.1498020 0.6973011 0.3875476
> ______________________________________________
> 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, MD
Alameda, CA, USA