Displaying 20 results from an estimated 20000 matches similar to: "how ot replace the diagonal of a matrix"
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
2011 Dec 15
2
Data Manipulation - make diagonal matrix of each element of a matrix
Dear R list,
I have the following data:
set.seed(1)
n <- 5 # number of subjects
tt <- 3 # number of repeated observation per subject
numco <- 2 # number of covariates
x <- matrix(round(rnorm(n*numco),2), ncol=numco) # the actual covariates
x
> x
[,1] [,2]
[1,] -0.63 -0.82
[2,] 0.18 0.49
[3,] -0.84 0.74
[4,] 1.60 0.58
[5,] 0.33 -0.31
I need to form a matrix
2008 Apr 12
3
Matrix Indexing
Hi
Does anyone know how I might pick out diagonal elements of a matrix using a
vector?
If I create a matrix a:
a <- matrix(c(1:16), 4, byrow=TRUE)
and I want to pick out the elements (1,1),(2,2),(3,3), or another arbitrary
diagonal (upper or lower), is there any way I can use a vector to do this?
So if I want a diagonal of size 3, I could create a vector like x <- c(0:2)
and then pick
2011 Jan 20
2
splitting a square symmetric matrix
So many matrices are square symmetrical (i.e. variance-covariance matrices),
is there any way to get R to split the matrix on its diagonal and just
return one diagonal?
So if I have
mat<-matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE)
is there anyway to get the lower right diagonal instead of the entire
symmetric matrix?
-------------------------------------------
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).
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
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
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
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]]
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
2005 Jul 12
3
elegant matrix creation
Hi
I want to write a little function that takes a vector of arbitrary
length "n" and returns a matrix of size n+1 by n+1.
I can't easily describe it, but the following function that works for
n=3 should convey what I'm trying to do:
f <- function(x){
matrix(c(
1 , 0 , 0 , 0,
x[1] , 1 , 0 , 0,
x[1]*x[2] , x[2] , 1 , 0,
2009 Aug 24
1
Filling matrix secondary diagonal
Hi,
how do i fill the secondary diagonals of a matrix?
Is there an funktion like the "diag" funktion in matlab, where i can specify
the diagonal i?d like to fill?
--
View this message in context: http://www.nabble.com/Filling-matrix-secondary-diagonal-tp25121745p25121745.html
Sent from the R help mailing list archive at Nabble.com.
2007 Oct 23
1
create diagonal matrix within a for cycle
? stato filtrato un testo allegato il cui set di caratteri non era
indicato...
Nome: non disponibile
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071023/b860b22b/attachment.pl
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
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
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
2011 Apr 12
5
B %*% t(B) = R , then solve for B
Hello,..
Apologies for the newbie question but...
I have a matrix R, and I know that *B %*% t(b) = R*
*I'm trying to solve for B *(aka. 'factoring the correlation matrix' I
think)
Please help!
I've read that 'to solve for B we define the eigenvalues of R and then
apply the techniques of Principal Component Analysis'
This made me reach for princomp() but now I'm
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
2008 Jun 05
1
Limit distribution of continuous-time Markov process
I have (below) an attempt at an R script to find the limit distribution
of
a continuous-time Markov process, using the formulae outlined at
http://www.uwm.edu/~ziyu/ctc.pdf, page 5.
First, is there a better exposition of a practical algorithm for doing
this? I have not found an R package that does this specifically, nor
anything on the web.
Second, the script below will give the right