search for: makematrix2

Displaying 2 results from an estimated 2 matches for "makematrix2".

2013 Oct 11
3
matrix values linked to vector index
Hi, In the example you showed: m1<- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or ?m1[!upper.tri(m1)] <-? rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1<- c(3,4,5) ?m2<- matrix(0,length(vec1),max(vec1)) ?indx <- cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE)) m2[indx]<- 1 ?m2 #???? [,1] [,2] [,3] [,4] [,5]
2011 Aug 01
4
fill Matrix quicker
dear all, i have a quite simple question, i want to fill up a Matrix like done in the following function, but the performance is very bad for large dimensions is there a way to do this like with apply or something similar? makeMatrix <- function(a, b,dim) { X=matrix(0,ncol=dim,nrow=dim) for (i in c(1:dim)){ for (j in c(1:dim)) { if (i==j) {X[i,j]<-a} else { X[i,j]<- exp((