Displaying 20 results from an estimated 11000 matches similar to: "Filling matrix secondary diagonal"
2004 Oct 13
2
diagonal matrix construction
Hi,
I have worked long and hard and looked in the manuals and am having a hard time constructing a diagonal matrix. I can get the diagonals out of a matrix but can't construct the matrix with just the diagonals. I have been on the web site and manuals and I think that it says to use:
dsj <- diag (three = 1, nrow, ncol = 7) three is the name of my matrix and
2011 Apr 04
1
Ordering every row of a matrix while ignoring off diagonal elements
Sorry if this is a stupid question but I've been stuck on how to code
so that I can order rows of a matrix without paying attention to the
diagonal elements.
Say, for example, I have a matrix d:
> d
[,1] [,2] [,3] [,4]
[1,] 0.000000 2.384158 2.0065682 2.2998856
[2,] 2.384158 0.000000 1.4599928 2.4333213
[3,] 2.006568 1.459993 0.0000000 0.9733285
[4,] 2.299886
2010 Mar 01
1
function odiag(): assigning values to off-diagonal
hi
I'm trying to use the function odiag(x) for matrix calculations. I would
like to assign new values to an off-diagonal in a matrix.
When I use the diag (x) function I could write something like
p<-matrix(seq(1:12),ncol=4)
p.new<-matrix(rep(0,12),ncol=4)
diag(p.new)<-diag(p)
p.new
But this won't work with odiag. How can I turn odiag (x) into something
like diag (x) in order
2007 Jun 20
1
How to extract diagonals
Hello,
I am using Mac OS X on a power book and R 2.5.0
I try to extract a diagonal from a dissimilarity matrix made with
dsvdis, with this code:
diag(DiTestRR)
But I get this error message:
Fehler in array(0, c(n, p)) : 'dim' spezifiziert ein zu großes Array
english:
Error in array(0, c(n, p)) : 'dim' specifies a too big array.
Is there a limit to extract diagonals?
I
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
2024 Dec 04
3
Undocumented behaviour of diag when replacing the diagonal of a matrix?
Dear list,
is anyone aware of the following behavious of diag when used to replace
diagonals (plural!) of a matrix?
Small example: The following is documented and clearly to be expected:
A <- matrix(0, nrow = 5, ncol = 5)
diag(A) <- 1; A
BUT, what about the following? When executing the code of `diag<-` line
by line, it throws errors. So why does it work?
diag(A[-1, ]) <- 2; A
2001 May 19
2
calculations on diagonals of a matrix
Given an nxm matrix A I want to compute the nxm matrix B whose ij-th
element is the sum of the elements of A lying on the diagonal that ends
with element ij, i.e.,
b_ij = a_ij + a_(i-1)(j-1) + a_(i-2)(j-2) + ...
In APL (which I no longer use), I would use the 'rotate' operator to derive
an array whose columns are diagonals of the given array and then cumulate
down columns. Is
2010 Apr 23
2
Matrix diagonal help
Hi
Suppose I have a matrix (cohort are rows and years are columns)
[2000] [2001] [2002] [2003]
[C1] 0.01 0.03 0.02 0.09
[C2] 0.06 0.05 0.07 0.11
[C3] 0.1 0.5 0.4 0.98
[C4] 0.7 0.6 0.2 0.77
I want to extracts the diagonals to get a matrix which looks like this (C1
becomes C2 in 2002, C2 becomes C3 in 2003
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]
2007 Aug 30
2
Need help putting histograms on the diagonal of a splom plot
Hello,
I am in need of help in putting histograms on the diagonal of a plot
produced with splom().
The plot matrix I am trying to produce is to have standard scatterplots
in the upper-left triangle, contour plots in the lower-right triangle,
and histograms on the diagonal. I have a function that does the first
two, but the histograms on the diagonal has been beyond my ability.
Here is my
2013 Apr 19
3
extracting the diagonal of an inverse matrix
Dear R-users,
I would like to know whether there is a way to extract a diagonal of an inverse matrix without computing the inverse of the matrix itself. The size of my matrices are really huge and, also using sparse matrix, computing the inverse leads to storage problems and low speed.
In other words, given a square matrix A, I aim to know diag(B), where B=solve(A), without computing solve(A).
2008 Oct 02
1
extracting diagonal from dist()
h <- structure(list(V1 = c(-0.351714766, 0.188298251, 0.042951816,
-0.072490327, -0.691885485, -0.816169763, -0.7066502, -0.856286332,
-0.839723411, -0.427242353, -0.372911996, 0.326707494, 0.07847893,
0.687447841, 0.516105863, 0.267076547, 0.727867663, 0.432699191,
0.258610632), V2 = c(0.256636068, -0.824072121, -0.149185618,
0.153280492, 0.01649528, 0.409410528, 0.286015324, 0.366323539,
2008 Nov 21
2
Extracting diagonal matrix
Dear All,
I have a correlation matrix of size 100 x 100 and would like to extract the diagonal matrix from it. I have used the for loop to store tha correlation values of the diagonal matrix. Is there a 'R way' of doing this?
Thanks in advance.
Kind regards,
Ezhil
2007 Feb 09
1
How to add the variable name to a qqplot or densityplot in the diagonal of an splom?
splom() doesn't complain here, but writes no names in the diagonal
boxes. What am I missing?
I believe that I need to add something like grid.text(x, ...) to the
diagonal panel, but I don't know how to get it cycle through the
column labels. And should
varname.col = 'blue', varname.cex = 1
be inside the diag.panel() function?
splom(szw[, n], pscales = 0,
diag.panel
2010 Sep 07
4
minor diagonal in R
Dear all,
seems that easy question but cannot find the function for that.
How to get the elements of the minor diagonal of the matrix?
Thanks a lot.
[[alternative HTML version deleted]]
2011 Jul 19
2
Taking all "complete" diagonals of a matrix
Hi R-Help!
I am trying to find a nicer way of extracting all the "complete" diagonals
of a matrix. I am working with very large matrices that have many more rows
than columns. I want to be able to extract each of the diagonals that are
as long as the number of columns in the matrix. I have written a rather
ugly function that presently does the job. It illustrates what I am trying
to
2010 Apr 23
3
reordering of matrix rows to maximize the sum of the diagonal
Hi r-help community,
This question isn't so much a syntax/coding one, but here goes:
Let's say I have matrix of arbitrary dimensions and I'd like to
reorder the rows in such a way that I could maximize the sum of the
entries along the diagonal.
For example, for this 3x3 matrix:
[,1] [,2] [,3]
[1,] 3 4 13
[2,] 9 1 2
[3,] 2 11 1
rearranging the rows
2013 Jan 23
2
setting off-diagonals to zero
The following 1460 x 1460 matrix can be throught of as 16 distinct 365 x 365
matrices. I'm trying to set off-diaganol terms in the 16 sub-matrices with
indices more than +/- 5 (days) from each other to zero using some for loops.
This works well for some, but not all, of the for loops. The R code I"m
using follows. For some reason the third loop below zero's-out everything
in the
2009 Feb 03
1
pairs() help - colour histograms on diagonal
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'd like to be able to colour histograms along the diagonal using the colours
stored in colnames(d):
> d
black blue brown cyan
1 0.96405751 -0.02964390 -0.060147424 -0.06460070
2 -0.03614607 0.95475444 -0.152382053 -0.07767974
3 -0.07095613 -0.05884884 -0.061289399 -0.06445973
4 -0.03708223 -0.05997624
2012 Aug 13
1
how to change variable names in corrgram diagonal
given this example
library(corrgram)
corrgram(mtcars[2:6], order=TRUE, upper.panel=panel.conf,
lower.panel=panel.pie,
diag.panel=panel.minmax,
text.panel=panel.txt)
how can I change the variable names in main diagonal?
(so that I can put more informative names of variables)
I think to understand that this should be done by modifing the panel.txt
function but