Skip to content
Prev 168965 / 398506 Next

New to R

It is not transposing (it just looks that way).  The first result is a vector which is 1 dimensional, but is neither a row or a column.  The printed version of it looks like a row, because that is a more compact representation.  If you sample enough points you will see it wrap around and be represented as several rows.  If it printed as a single column, then the first values would scroll off the screen with only a moderate number of values.

The replicate function then takes these vectors and combines them into a matrix and just happens to use each vector as a column of the new matrix, this is standard, matrices by default are filled by column, look at the output of as.matrix( sample( 6, 4, replace=TRUE ) ) and you will see your vector converted to a matrix of 1 column.  It could have been done the other way, but way back the decision was made to do it this way and there are probably a lot of things that would break if it were changed now, so we get to live with it.  A single call to 't' is not too much effort to get what we expect.

So in short, a vector is neither a column or a row, but prints as a row for practical reasons, and is converted to a column by default if made into a matrix.  

Hope this helps,