It concerns trival diagonal matrices:> diag(1)[,1] [1,] 1> diag(rnorm(1))<0 x 0 matrix>> diag(rnorm(1),nrow=1)[,1] [1,] 0.4843697 There's an obvious work around... but I thought it was worth notifying the list. Regards, John Marsland ********************************************************************** This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}}
On Wednesday, September 17, 2003, at 06:51 PM, Marsland, John wrote:> It concerns trival diagonal matrices: > [...] >> diag(rnorm(1)) > <0 x 0 matrix> > >> diag(rnorm(1),nrow=1) > [,1] > [1,] 0.4843697 > > There's an obvious work around... but I thought it was worth notifying > the > list.I fail to see any reason for you posting this here, since this is a perfectly documented behavior - ?diag says: Note: Using 'diag(x)' can have unexpected effects if 'x' is a vector that could be of length one. Use 'diag(x, nrow = length(x))' for consistent behaviour. Hence you can safely assume that the "list" needs no notification of this. Cheers, Simon
Why is this a bug ? help(diag) says If 'x' is a vector (or 1D array) of length two or more, then 'diag(x)' returns a diagonal matrix whose diagonal is 'x'. If 'x' is a vector of length one then 'diag(x)' returns an identity matrix of order the nearest integer to 'x'. The dimension of the returned matrix can be specified by 'nrow' and 'ncol' (the default is square). There's no way of knowing what rnorm(1) returned in your particular call, but my guess is that the integer "nearest" to it was 0. On Wednesday 17 September 2003 11:51, Marsland, John wrote:> It concerns trival diagonal matrices: > > diag(1) > > [,1] > [1,] 1 > > > diag(rnorm(1)) > > <0 x 0 matrix> > > > diag(rnorm(1),nrow=1) > > [,1] > [1,] 0.4843697 > > There's an obvious work around... but I thought it was worth notifying the > list. > > Regards, > > John Marsland > > > ********************************************************************** > This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}} > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel