[R] matrix dimension and for loop

ggrothendieck@yifan.net ggrothendieck at yifan.net
Wed Apr 10 18:06:35 CEST 2002


On 10 Apr 2002 at 16:47, Uwe Ligges wrote:

> ggrothendieck at yifan.net wrote:

> > 1. Matrix multiplication. Note that if x is a vector then it is treated as a
> >    one column matrix.  Also note that NROW(x) is the same as nrow(x), if x is a
> >    matrix; however, if x is a vector, then NROW(x) is its length while nrow(x)
> >    is NULL.  Thus it is important here to use NROW and not nrow. This is
> >    discussed in the help on nrow.
> > 
> >         x %*% diag(y,NROW(x))
> 
> 
> Not quite. The number of *columns* of x, ncol(x), is interesting here,
> not NROW(x),
> or just use length(y) instead of ncol(x) ....

Thanks for pointing out this error.  Note, however, that NROW(x) should
be NCOL(x), and not ncol(x), since x can be a vector.   length(y) is
probably best.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list