similar to: Matrix building to remove for loops

Displaying 20 results from an estimated 7000 matches similar to: "Matrix building to remove for loops"

2011 Mar 28
1
rtree() distances between tips as n by n matrix?
Hello R users, If I generate a random tree with n=10 tips as rtree(n=10) say, is there a way to have the distances between all tips put into a n by n matrix? Sincerely, Brian [[alternative HTML version deleted]]
2011 Mar 26
2
Building a matrix so that matrix(r, c)<-matrix(c, r) with No For Loops
Hello, I would like to take advantage of the upper.tri() function here but I don't know exactly. Here is some working code... i<-5 fi<-matrix(0,nrow=i,ncol=i) 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] } } } So far I know I can simplify this code to 5 lines (no for loops): i<-5
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
2005 Jan 20
3
Constructing Matrices
Dear List: I am working to construct a matrix of a particular form. For the most part, developing the matrix is simple and is built as follows: vl.mat<-matrix(c(0,0,0,0,0,64,0,0,0,0,64,0,0,0,0,64),nc=4) Now to expand this matrix to be block-diagonal, I do the following: sample.size <- 100 # number of individual students I<- diag(sample.size) bd.mat<-kronecker(I,vl.mat) This
2006 Nov 10
4
Selective subsetting
Hi all, Here's an interesting (for me, at least!) problem I came across: I have a correlation matrix, let's say with 6 variables, A to F, as column headings and the same 6 as row headings. The matrix is filled with correlation coefficients. Therefore, the diagonal is all 1's, and each of the two triangles formed by the diagonal has the same 15 correlation coefficients. I need to
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? -------------------------------------------
2011 Apr 27
1
matrix of higher order differences
Is there an easy way to turn a vector of length n into an n by n matrix, in which the diagonal equals the vector, the first off diagonal equals the first order differences, the second... etc. I.e. to do this more efficiently: diffmatrix <- function(x){ n <- length(x); M <- diag(x); for(i in 1:(n-1)){ differences <- diff(x, dif=i); for(j in 1:length(differences)){ M[j,i+j]
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
2016 Jan 16
2
heatmap de matriz diagonal inferior
Tengo una matriz de de datos (correlación) entre pares de muestras, de tipo diagonal inferior, de 250 y quisiera hacer un heatmap y/o un dendrograma. Soy un poco novato y me encuentro con el problema que no se como "importarla" para cargarla e indicar que se trata de una matriz de datos de tipo "diagonal inferior" para que R lo interprete y poder realizar un heatmap y/o
2009 Nov 16
2
violin - like plots for bivariate data
I'm attempting to produce something like a violin plot to display how y changes with x for members of different groups (My specific case is how floral area changes over time for several species of plants). I've looked at panel.violin (in lattice), which makes nice violin plots, but is really set up to work on a single variable - the area trace represents the frequency of each value of x
2009 Jul 14
5
Nested for loops
Hi, I have spent some time locating a quite subtle (at least in my opinion) bug in my code. I want two nested for loops traversing the above-diagonal part of a square matrix. In pseudo code it would something like for i = 1 to 10 { for j = i+1 to 10 { // do something } } However, trying to do the same in R, my first try was for (i in 1:10) { for (j in (i+1):10) { //
2003 Dec 20
6
Notice for you
..::: Drunk Young :::... http://210.101.95.254/drunk-young ^^^^ ^^^^ Click here to Join Drunk Young will take you to the new level of excitement. It is a guarantee of Your pleasure, because we choose models very seriously & carefully, depending on you offers and suggestions. 'Drunk Young' is regularly updates to bring you more and more sweet nymphets 100%
2003 May 22
7
extract half a matrix
Dear all, I'm new to matrix operations in R. I couln't find a solution to the following problem among earlier help mails or in An introd to R, I guess because the question is really basic. I want to extract all above the diagonal, i.e. from 1 2 3 4 1 0 26 49 49 2 26 0 44 40 3 49 44 0 21 4 49 40 21 0 I want 26 49 44 49 40 21 Thanks in advance! Sincerely, Tord
2010 Apr 30
2
Flattening and unflattening symmetric matrices
Here's an easy question: I'd like to convert a symmetric matrix to a vector composed of the upper.tri() part of it plus the diagonal, and convert it back again. What's the best way to achieve this? I'm wondering if there are some built in functions to do this easily. I can encode fine: v <- c(diag(A),A[upper.tri(A)]) but I don't see an easy way to recover A from v
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
2008 Jul 18
5
Reading SPSS .por files
Does anyone know how to read SPSS .por (ie Portable) files? The foreign package only deals with SPSS .sav files and not with those with a "por" extension. Thanks, José Mr José Luis Iparraguirre D'Elia Senior Research Economist Economic Research Institute of Northern Ireland Floral Buildings 2 - 14 East Bridge Street Belfast BT1 3NQ Northern Ireland United Kingdom
2006 Jan 14
1
(no subject)
I am having difficulty installing the package "lattice". First I tried downloading it from the CRAN site (in the normal way) : the message said it worked but when I typed library I got an error message ("there is no package"). Second I tried installing it from the local zip. I have reproduced the result below. utils:::menuInstallLocal() package 'lattice'
2011 Jan 25
1
NA printing
Hi. I'm writing a print method for an object that includes a numeric matrix for which the lower diagonal elements are not meaningful. So I make the lower diagonal of my matrix NA and print it. But my co-author does not like NA there and wants a dash. I have tried coercing the matrix to character, essentially by M[is.na(M)] <- "-" but this interferes with the pleasing column
2006 Jan 27
3
[Q] extracting lower diagonal elements of a matrix
Hi R users I like to extract lower diagonal elements of a matrix in such a way like, data[1,2], data[1,3], ...., data[5,6] are extracted from a matrix called 'data' This short script below is what I have written so far. ########################################## data <- matrix(rnorm(36,0,1),nrow=6) temp<-c() for (i in 1:(nrow(data)-1)) { for (j in (i+1):nrow(data)) {
2007 Nov 29
1
?eigen documentation suggestion
from ?eigen symmetric: if 'TRUE', the matrix is assumed to be symmetric (or Hermitian if complex) and only its lower triangle is used. If 'symmetric' is not specified, the matrix is inspected for symmetry. I think that could mislead a naive reader as it suggests that, with symmetric=TRUE, the result of eigen() (vectors and values) depends only on