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

Charles C. Berry cberry at tajo.ucsd.edu
Thu Nov 6 21:34:30 CET 2008


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 )

instead of as.matrix( your.result )

HTH,

Chuck

>
> I mean, it's not extremely a problem,
> because there are not many loops aroud it,
> but it looks somehow ugly. :(
>
> Ciao,
>  Oliver
>
> ______________________________________________
> 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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list