similar to: how to do pairwise sums in a matrix

Displaying 20 results from an estimated 20000 matches similar to: "how to do pairwise sums in a matrix"

2007 Jul 28
8
generating symmetric matrices
Greetings, I have a seemingly simple task which I have not been able to solve today. I want to construct a symmetric matrix of arbtriray size w/o using loops. The following I thought would do it: p <- 6 Rmat <- diag(p) dat.cor <- rnorm(p*(p-1)/2) Rmat[outer(1:p, 1:p, "<")] <- Rmat[outer(1:p, 1:p, ">")] <- dat.cor However, the problem is that the matrix
2008 Mar 10
1
How can I sample from a two-dimensional grid of points
Hi everyone, My goal is to sample from a two-dimensional grid. Consider the following example of code: n.grid <- 500 muA.grid <- seq(-4,4, length=n.grid) muB.grid <- seq(-4,4, length=n.grid) mu.p <- matrix(NA, nrow=n.grid, ncol=n.grid) for(i in 1:n.grid){ for(j in 1:n.grid){ mu.p[i,j] <- dnorm(muA.grid[i], 0, 1)*dnorm(muB.grid[j], 0, 0.5) } } mu.p <-
2010 Sep 10
3
Is there a bisection method in R?
Dear fellow R-users, Is there a function that does the bisection method? I was unable to find one. Thanks in advance. Gregory [[alternative HTML version deleted]]
2005 Jun 25
2
optimization problem in R ... can this be done?
Im trying to ascertain whether or not the facilities of R are sufficient for solving an optimization problem I've come accross. Because of my limited experience with R, I would greatly appreciate some feedback from more frequent users. The problem can be delineated as such: A utility function, we shall call g is a function of x, n ... g(x,n). g has the properties: n > 0, x lies on the
2008 Jan 14
3
Listing the data contents of a package
Hi R users, Simply question: On the command line, how do I list the datasets contained within a package, e.g. MASS? I scanned the mailing list history but was unable to find the answer. Thanks in advance. Gregory --------------------------------- [[alternative HTML version deleted]]
2009 Oct 06
4
Text editors for Sweave (rnw) files
Hi fellow R-users, Are there any text editors that recognize sweave (.rnw) files? I am running Windows Vista and in the past I used Tinn-R for R files but it (surprisingly) doesn't recognize rnw files and does not do any syntax highlighting for them. Thanks in advance, Greg __________________________________________________________________ Make your browsing faster, safer, and
2007 Jul 30
3
Constructing correlation matrices
Greetings, I have a seemingly simple task which I have not been able to solve today and I checked all of the help archives on this and have been unable to find anything useful. I want to construct a symmetric matrix of arbtriray size w/o using loops. The following I thought would do it: p <- 6 Rmat <- diag(p) dat.cor <- rnorm(p*(p-1)/2) Rmat[outer(1:p, 1:p, "<")] <-
2004 Jul 30
2
pairwise difference operator
There was a BioConductor thread today where the poster wanted to find pairwise difference between columns of a matrix. I suggested the slow solution below, hoping that someone might suggest a faster and/or more elegant solution, but no other response. I tried unsuccessfully with the apply() family. Searching the mailing list was not very fruitful either. The closest I got to was a cryptic chunk
2009 Jan 07
4
Another newbie question
Problem: I have a data frame with 1s and 0s denoting presence/absence of species (columns) for particular plot measurements (rows). What I want to do is make a new column whose entries for each row is a list of the column names in which a species is present (ie. for row one its entry might read: "sp1","sp2", etc.). I've tried various functions etc. but can't seem to
2008 Mar 14
2
using nrow to identify one row
Hi fellow R-users, I have run into a problem when trying to identify the number of rows in a matrix. Say we have an arbitrary 5 by 5 matrix called temp: temp <- matrix(norm(25), nrow=5) The problem is that nrow(temp[1,]) returns NULL. I would like it to return 1 because in my larger program I am indexing the rows of large matrices according to another variable and I need to test when the
2006 Jun 15
1
individual scales in random subset of pairwise distance survey
Hello, I'm curious if anyone has encounted a version of this problem (and it's solution) involving finding a consistent set of scales for subsets of survey data. The goal is to obtain peoples' rankings of pairwise similarity of a large number of items, on a 1..5 scale for example, and average these across people to use as input to MDS: How similar is object A to B on a 1..5
2006 Aug 08
3
Pairwise n for large correlation tables?
Hello, I'm using a very large data set (n > 100,000 for 7 columns), for which I'm pretty happy dealing with pairwise-deleted correlations to populate my correlation table. E.g., a <- cor(cbind(col1, col2, col3),use="pairwise.complete.obs") ...however, I am interested in the number of cases used to compute each cell of the correlation table. I am unable to find such a
2008 Mar 30
2
Alignment and Reshaping of the matrix
Dear R users, I have a matrix like 85 .90 86 .89 87 .98 86 .87 88 .98 90 .78 88 .76 89 .56 90 .67 95 .67 89 .89 90 .87 91 .56 96 .87 90 .76 92.98 each pair of columns present a variable name and next the value. I have matrix with more than 500 rows and column. Now I want to convert this matrix in to. 85 .90 00 .00 00 86 .00 .89 .00 .87 87 .00 00 .98 00 88 .98 00 .76
2006 Mar 25
2
pairwise combinatons of variables
Dear WizaRds, although this might be a trivial question to the community, I was unable to find anything solving my problem in the help files on CRAN. Please help. Suppose I have 4 variables and want to use all possible combinations: 1,2 1,3 1,4 2,3 2,4 3,4 for a further kmeans partitioning. I tried permutations() of package e1071, but this is not what I need. Thank you for your help and
2010 Jul 11
2
simple apply syntax
I know this is a simple question, but I have yet to master the apply statements. Any help would be appreciated. I have a column of probabilities and sample sizes, I would like to create a column of binomial random variables using those corresponding probabilities. Eg. mat = as.matrix(cbind(p=runif(10,0,1), n=rep(1:5))) p n [1,] 0.5093493 1 [2,] 0.4947375 2 [3,]
2010 Jan 27
3
Function for describing segements in sequential data
Dear R-users, Say that I have a sequence of zeroes and ones: x <- c(1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0) The sequences of ones represent segments and I want to report the starting and endpoints of these segments. For example, in 'x', the first segment starts at location 1 and ends at 3, and the second segment starts at location 8 and ends at location 10. Is there an efficient
2004 Nov 23
5
number of pairwise present data in matrix with missings
is there a smart way of determining the number of pairwise present data in a data matrix with missings (maybe as a by-product of some statistical function?) so far, i used several loops like: for (column1 in 1:99) { for (column2 in 2:100) { for (row in 1:500) { if (!is.na(matrix[row,column1]) & !is.na(matrix[row,column2])) { pairs[col1,col2] <- pairs[col1,col2]+1
2005 Jul 28
3
using integrate with optimize nested in the integration
Hi guys im having a problem getting R to numerically integrate for some function, say f(bhat)*optimize(G(bhat)), over bhat. Where id like to integrate this over some finite range, so that here as we integrate over bhat optimize would return a different optimum. For instance consider this simple example for which I cannot get R to return the desired result: f <- function(bhat) exp(bhat) g
2013 Jan 10
6
sort matrix based on a specific order
Hi I have a character matrix with 2 columns A and B, If I want to sort the matrix based on the column B, but based on a specific order of characters: mat<-cbind(c('w','x','y','z'),c('a','b','c','d')) ind<-c('c','b','d','a') I want "mat" to be sorted by the sequence in "ind":
2007 Nov 21
2
matrix elementwise average with NA's
Hello fellow R users, I have a matrix computation that I imagine should be relatively easy to do, however I cannot figure out a nice way to do it. I have two matrices, for example mat1 <- matrix(c(1:5,rep(NA,5), 6:10), nrow=3, byrow=T) mat2 <- matrix(c(2:6, 6:10, rep(NA,5)), nrow=3, byrow=T) I'd like to compute the element-wise average for non-NA entries. Of course (mat1+mat2)/2