similar to: Building a matrix so that matrix(r, c)<-matrix(c, r) with No For Loops

Displaying 20 results from an estimated 40000 matches similar to: "Building a matrix so that matrix(r, c)<-matrix(c, r) with No For Loops"

2011 Mar 15
1
Matrix building to remove for loops
Hello R users, I would like to reduce the number of for loops in my code. I build these matrices (50000 times). The main diagonal are 1s and the two sides along the main diagonal mirror each other as follows: i<-5 fi<-matrix(0,nrow=i,ncol=i)#floral inhibition matrix for(r in 1:i){ for(c in 1:i){ if(r==c){ fi[r,c]<-1 }else if(r<c){ fi[r,c]<-1-runif(1)^.5 }else{ fi[r,c]<-fi[c,r]
2011 Feb 09
2
Generate multivariate normal data with a random correlation matrix
Hi All. I'd like to generate a sample of n observations from a k dimensional multivariate normal distribution with a random correlation matrix. My solution: The lower (or upper) triangle of the correlation matrix has n.tri=(d/2)(d+1)-d entries. Take a uniform sample of n.tri possible correlations (runi(n.tr,-.99,.99) Populate a triangle of the matrix with the sampled correlations Mirror the
2007 Feb 07
2
blank upper or lower triangle of cor-matrix
Dear altogether, I want to blank the lower (or upper) part of a correlation matrix as it is done by dist() example: ( d <- cor(matrix(runif(12),nrow=4)) ) If I do the following d[lower.tri(d)] <- "" of course everything is changed to character - that's not what should be. Additionally, it does not work to assign "0" or anything else. The same is true for
2004 Nov 06
3
how to read this matrix into R
the following the the lower.tri matrix in a file named luxry.car and i want to read it in R as a lower.tri matrix.how can i do? i have try to use help.search("read"),but no result what i want. 1.000 0.591 1.000 0.356 0.350 1.000
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 Mar 18
3
exploring dist()
Hello, everybody, I hope somebody could help me with a dist() function. I have a data frame of size 2*4087 (col*row), where col corresponds to the treatment and rows are species, values are Hellinger distances, I should reconstruct a distance matrix with a dist() function. I know that "euclidean" method should be used. When I type: dist(dframe,"euclidean") it gives me a
2005 Mar 01
2
almost lower triangular matrices
I have output from a program which produces a distance matrix I want to read into a clustering program in R. The output is a .txt file and is 'almost' lower triangular in the sense that it is just the triangle below the diagonal. So for example a 4-by-4 distance matrix appears as, 1 2 3 4 5 6 i.e. it looks like a lower triangular of a 3-by3. I thought I might be able
2011 Oct 10
4
correlation matrix
Hello Gurus I have two correlation matrices 'xa' and 'xb' set.seed(100) d=cbind(x=rnorm(20)+1, x1=rnorm(20)+1, x2=rnorm(20)+1) d1=cbind(x=rnorm(20)+2, x1=rnorm(20)+2, x2=rnorm(20)+2) xa=cor(d,use='complete') xb=cor(d1,use='complete') I want to combine these two to get a third matrix which should have half values from 'xa' and half
2007 Aug 16
6
an easy way to construct this special matirx
Hi, Sorry if this is a repost. I searched but found no results. I am wondering if it is an easy way to construct the following matrix: r 1 0 0 0 r^2 r 1 0 0 r^3 r^2 r 1 0 r^4 r^3 r^2 r 1 where r could be any number. Thanks. Wen [[alternative HTML version deleted]]
2012 Oct 26
1
Creating a correlation matrix from a vector
I'm looking to create a correlation matrix, but I have already obtained the correlations, which are stored in a vector. (Basically, I'm running a simulation which requires a correlation matrix, but I am simulating the various correlations.) My aim is to create a function that can take the vector, and fit the values into their respective locations in a correlation matrix. (The correlations
2012 Feb 15
3
built a lower triangular matrix from dataframe
Hello! I'm trying to build a lower triangular matrix (with zeros in the diagonal) from a particular dataframe. The matrix I have to construct has 203 rows and 203 columns and that makes 20503 values to be included within (that's why I can't do it manually). To illustrate the dataframe I have, I'll give you an example of a dataframe and matrix with dimensions 6x6 (to make it
2000 Jul 07
2
Question of programming style
This is really a question of how to program this *BETTER*. It works as I have done it, but is quite ugly. I want to do a 3d scatterplot of the upper triangle of a matrix, where the z-values are the values in the matrix, and the row and column indices are the y- and x-values. The complete (11 by 11) matrix is mmtop94.2. Here is my awkward code: mmtop94.2[lower.tri(mmtop94.2)] <- NA # Here i
2009 Nov 27
2
Symmetric Matrix classes
Hi, I'd like to store large covariance matrices using Matrix classes. dsyMatrix seems like the right one, but I want to specify just the upper/lower triangle and diagonal and not have to instantiate a huge n^2 vector just for the sake of having half of it ignored: Dumb example: M <- new("dsyMatrix", uplo="U", x=rnorm(1e4), Dim=as.integer(c(100, 100))) diag(M) <- 1
2002 Oct 08
2
sem (lisrel) - starting problems
Hi, (1.) How is it possible to get automatic a "lower triangle of correlation matrix" ? h.cor <- cor(dat,use="pairwise.complete.obs") zz <- lower.tri(h.cor,diag=T) ### that's not what i wish and "wrong" ? results <- matrix(unlist(h.cor[upper.tri(h.cor,diag=T)])) results <- matrix(unlist(h.cor[upper.tri(h.cor,diag=T)]),5) Must i take the lowest
2011 Jun 02
4
generating random covariance matrices (with a uniform distribution of correlations)
List members, Via searches I've seen similar discussion of this topic but have not seen resolution of the particular issue I am experiencing. If my search on this topic failed, I apologize for the redundancy. I am attempting to generate random covariance matrices but would like the corresponding correlations to be uniformly distributed between -1 and 1. The approach I have been using is:
2004 Nov 25
4
Avoiding for-loops
Hello R-users, I have a symmetric matrix of numerical values and I want to obtain those values in the upper or lower triangle of the matrix in a vector. I tried to do the job by using two for-loops but it doens't seem to be a clever way, and I'd like to know a more efficient code for a large matrix of thousands of rows and columns. Below is my code for your reference. Thanks a lot.
2003 Jul 03
2
SVD and spectral decompositions of a hermitian matrix
Hi: I create a hermitian matrix and then perform its singular value decomposition. But when I put it back, I don't get the original hermitian matrix. I am having the same problem with spectral value decomposition as well. I am using R 1.7.0 on Windows. Here is my code: X <- matrix(rnorm(16)+1i*rnorm(16),4) X <- X + t(X) X[upper.tri(X)] <- Conj(X[upper.tri(X)]) Y <-
2005 Dec 03
1
Correlation matrix from a vector of pairwise correlations
I've a vector of pairwise correlations in the order low-index element precedes the high-index element, say: corr(1,2)=0.1, corr(1,3)=0.2, corr(2,3)=0.3, corr(3,4)=0.4 How can I construct the corresponding correlation matrix? I tried using the "combn"-function in "combinat" package: library(combinat) combn(c(0.1,0.2,0.3,0.4),2) , but to no avail... Thank you for your
2004 Sep 23
7
decompose a correlation matrix
Is there a simple way to decompose the upper triangle of a correlation matrix to a linear list; For example: X Y Z X 1 2 3 Y 2 1 4 Z 3 4 1 so you get a list like: xy 2 XZ 3 YZ 4 I suspect you can do it with a matrix transformation, but that beyond me at present. Many thanks Mark _________________________ Department of Molecular and Human Genetics, Baylor College of Medicine,
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