[R] replicate and as.matrix: different behaviour between batch and non-batch mode

Oliver Bandel oliver at first.in-berlin.de
Fri Nov 7 01:07:41 CET 2008


Hi,

Zitat von "Charles C. Berry" <cberry at tajo.ucsd.edu>:

> On Thu, 6 Nov 2008, Oliver Bandel wrote:
>
> > Hello Charles,
> >
>
> [snip]
>
> >> 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?
>
>
> use
>  	matrix( your.result , nc = n.replicates )
>
> or
>
>  	dim( your.result ) <- c( n.samples, n.replicates )
[...]

Aaaah, OK!

Yes, using dim() makes sense.

Good hint!

Thanks!


Ciao,
   Oliver



More information about the R-help mailing list