[R] replicate and as.matrix: different behaviour between batch and non-batch mode
Oliver Bandel
oliver at first.in-berlin.de
Thu Nov 6 17:46:14 CET 2008
Hello Charles,
thank you for the hint.
Zitat von "Charles C. Berry" <cberry at tajo.ucsd.edu>:
[...]
> > This looks good (and correct to me).
>
> Look again .
>
> It is not the same as what you have above.
[...]
OK, yes, you are right!
I mixed the two parameters...
Now I get the same problem also at the shell directly typed in:
=====================
> as.matrix( replicate(10, sample(x, 3) ) )
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 12 15 3 12 7 4 4 14 6 20
[2,] 6 11 1 4 6 19 17 11 19 11
[3,] 20 17 6 8 3 14 19 10 2 14
>
> as.matrix( replicate(10, sample(x, 2) ) )
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 4 17 18 14 6 11 5 17 13 13
[2,] 14 3 16 12 17 7 20 16 2 17
>
> as.matrix( replicate(10, sample(x, 1) ) )
[,1]
[1,] 19
[2,] 17
[3,] 12
[4,] 14
[5,] 12
[6,] 13
[7,] 18
[8,] 12
[9,] 5
[10,] 20
> dim( as.matrix( replicate(10, sample(x, 3) ) ) )
[1] 3 10
> dim( as.matrix( replicate(10, sample(x, 2) ) ) )
[1] 2 10
> dim( as.matrix( replicate(10, sample(x, 1) ) ) )
[1] 10 1
>
=====================
So, the behaviour is the same...
...but is not really that fine. :(
...how could I avoid the necessity of the transposition
of the matrix in the case of only one sample?
I mean, it's not extremely a problem,
because there are not many loops aroud it,
but it looks somehow ugly. :(
Ciao,
Oliver
More information about the R-help
mailing list