similar to: RFC: diag(x, n) not preserving integer and logical x

Displaying 20 results from an estimated 10000 matches similar to: "RFC: diag(x, n) not preserving integer and logical x"

2014 Aug 11
0
diag(x, n) not preserving integer and logical x
Martin Maechler wrote: > diag(x) preserves the storage mode of x for 'complex' and > 'double' precision, but converts integer and logicals to double : Duncan Murdoch wrote: > I think the change to preserve integer makes sense, but preserving > logical does not. A diagonal matrix has zeros off the diagonal, and > they are not logical. Having diag() sometimes
2003 Sep 17
2
possible bug in diag()
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
2013 Apr 09
2
Behaviors of diag() with character vector in R 3.0.0
Dear all, According to CHANGES IN R 3.0.0: o diag() as used to generate a diagonal matrix has been re-written in C for speed and less memory usage. It now forces the result to be numeric in the case diag(x) since it is said to have 'zero off-diagonal entries'. diag(x) does not work for character vector in R 3.0.0 any more. For example, v <- c("a",
2000 May 25
1
diag() (PR#555)
Full_Name: David Duffy Version: 1.0.1 OS: Linux Submission from: (NULL) (152.98.96.21) Documentation for diag() states that "If x is a vector (or a 1-d array) then diag(x) returns a diagonal matrix whose diagonal is x." > m<-matrix(1:4,ncol=1) > diag(m) [1] 1 diag(as.vector(m)) gives the advertised performance. Fix: Change documentation.
2013 May 01
1
diag() when input is a numeric scalar
Hi All, I'm wondering why when passing a single numeric value that contains any decimals to diag() that the value is silently coerced to a integer for constructing an identify matrix. To me, an input like diag(5.435) seems fairly ambiguous and is more than likely a programming mistake, since it's not obvious that a 5x5 identity matrix should be created. I've seen some code where other
1998 Sep 09
2
diag() losing dimnames
Using diag() to extract the diagonal of a matrix loses all but the first dimname (R 0.62.3). The problem seems to be in [ ]: > > x <- matrix(1:9,3,3) > dimnames(x) <- list(c("a", "b", "c"), c("a", "b", "c")) > x a b c a 1 4 7 b 2 5 8 c 3 6 9 > diag(x) a NA NA 1 5 9 > x[c(1,5,9)] a NA NA 1 5 9 > Paul
2005 Oct 19
3
diag() problem
Hi I have a matrix "u", for which diag() gives an error: u <- structure(c(5.42334674128216, -2.31319389204264, -5.83059042218476, -1.64112369640695, -2.31319389212801, 3.22737617646609, 1.85200668021569, -0.57102273078531, -5.83059042231881, 1.85200668008156, 11.9488923894962, -3.5525537165941, -1.64112369587405, -0.571022730886046, -3.55255371755604,
2015 May 13
1
Why is the diag function so slow (for extraction)?
> From: Martin Maechler <maechler at lynne.stat.math.ethz.ch> > diag() should not work only for pure matrices, but for all > "matrix-like" objects for which ``the usual methods'' work, such > as > as.vector(.), c(.) > > That's why there has been the c(.) in there. > > You can always make code faster if you write the code so it only >
2004 Jan 12
1
Matrix indexes
Two questions about matrix indexing: Is is correct that V <- V[lower.tri(V, diag=TRUE)] returns the lower triangular of matrix V, that is: all elements above diagonal are set to zero? I understand that the triangle of matrix elements of V for which lower.tri is TRUE are returned while the others (above diagonal) are set to zero (or NA ???). If D and B are vectors of logicals, what
2011 Jul 02
1
Error when using plot in diag.panel argument of pairs
 Dear Madame or Sir,I am having a problem in combining density-smoothed scatterplot matrices with a plot of kernel destiny estimations of each dimension plotted on the respective field of the diagonal.I have tried following approach using the package "sm" for the kernel density estimation, as well as "MASS" respectively:pairs(myTable[, 1:4],panel=function(x,y, ...){
2010 Jan 07
1
"diag", "diag<-" and "[" , "[<-"
Dear all I have the following problem. M <- matrix(0,3,3) # dimension of M is dinamic and this can lead to the next subscript diag(M[1,1]) <- rep(100,1) #Error in `diag<-`(`*tmp*`, value = 100) : # only matrix diagonals can be replaced diag(M[1,1,drop=F]) <- rep(100,1) #Error in diag(M[1, 1, drop = F]) <- rep(100, 1) : # incorrect number of subscripts diag(M[2:3,1:2]) <-
2006 Oct 03
4
how ot replace the diagonal of a matrix
Dear useRs, Trying to replace the diagonal of a matrix is not working for me. I want a matrix with .6 on the diag and .4 elsewhere. The following code looks like it should work--when I lookk at mps and idx they look how I want them too--but it only replaces the first element, not each element on the diagonal. mps <- matrix(rep(.4, 3*3), nrow=n, byrow=TRUE) idx <- diag(3) mps idx mps[idx]
2009 Aug 26
1
Problem with standard generic methods in Matrix package
I have posted this message on r-lang, but it is perhaps more appropriate on r-devel: --- Hello, I'm puzzled by a problem with call to diag(), rowSums(), rownames() on objects of class "dgtMatrix", created by sparseMatrix() or spMatrix(). I use Matrix 0.999375-30. The weird thing is that I don't encounter any problem when I use this functions on the R prompt, or
2004 Oct 01
2
multiple dimensional diag()
Hi I have two arbitrarily dimensioned arrays, "a" and "b", with length(dim(a))==length(dim(b)). I want to form a sort of "corner-to-corner" version of abind(), or a multidimensional version of blockdiag(). In the case of matrices, the function is easy to write and if a=matrix(1,3,4) and b=matrix(2,2,2), then adiag(a,b) would return: [,1] [,2] [,3] [,4] [,5]
2007 Oct 10
3
as.dist with diagonal unequal zero
Hello and sorry that I still haven?t found a solution for my problem. I need to extract the lower and upper triangle from a square matrix including the diagonal. This diagonal is not zero in that special case. I tried with as.dist w<-as.dist(w, diag = TRUE) > w 1 2 3 4 5 1 0 2 2 0 3 3 8 0 4 4 9 14 0 5 5 10 15 20 0 but found no way to keep the diagonal that is in the
2003 Oct 01
4
Solving a tridiagonal system
I need to find solutions to a tridiagonal system. By this I mean a set of linear equations Ax = d where A is a square matrix containing elements A[i,i-1], A[i,i] and A[i,i+1] for i in 1:nrow, and zero elsewhere. R is probably not the ideal way to do this, but this is part of a larger problem that requires R. In my application it is much easier (and much faster) to generate the diagonal and
2005 Mar 31
4
NA's?
Your message doesn't help us very much. You haven't said what kind of calculation it is you want to do, and that certainly matters. For example, for some kinds of computations the solution you started below would work fine: > M <- matrix(1:16, 4, 4) > is.na(diag(M)) <- TRUE > M [,1] [,2] [,3] [,4] [1,] NA 5 9 13 [2,] 2 NA 10 14 [3,] 3 7 NA
2009 Mar 11
3
Matrix Construction; Subdiagonal
I'm trying to enter a vector into the subdiagonal of a matrix but cannot find a command in R which corresponds to the MatLab version of diag(vec, k), where vec = the vector of interest, and k = the diagonal (k=0 for the diagonal; k=-1 for the subdiagonal; k=1 for superdiagonal, etc.) Is there an equivalent command in R? I'm looking for something like this: vec = seq(1, 5, 1)
2006 Jan 28
1
Complex Matrix Exponentials.
Hello, I was curious if there was a complex valued matrix exponential function available for R? I have some Laplace transforms of occupation times for a hidden Markov model. The matrix exponential function in the msm package does not seem to handle complex values. For example > MatrixExp(diag(1i,2)) [,1] [,2] [1,] 1 0 [2,] 0 1 Warning message: imaginary parts
2015 May 04
2
Why is the diag function so slow (for extraction)?
(I asked this question on StackOverflow <http://stackoverflow.com/q/30035939/1191259> a short time ago; sorry if you're seeing it again. Feel free to answer there as well if you like. The code formatting and such on that site can be nice.) I benchmarked matrix and vector subsetting to extract the diagonal of a square matrix against the diag() function, and the latter lost by a wide