Displaying 2 results from an estimated 2 matches for "makemat".
Did you mean:
makemap
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]
2008 May 09
0
applying cor.test to a (m, n) matrix - SUMMARY
...relations have correct values. And of course this changes the lower and upper limits to 0 instead of 1 as well, although the p-value is correct in this case. Sincerely I don't see why that is. I will provide his example as well with the same m matrix I used above:
mydat = m
n = dim(mydat)[2]
makemat = function(fun){
cc = combn(n,2)
results = apply(cc,2,function(x)cor.test(mydat[,x[1]],mydat[,x[2]]))
answer = matrix(0,n,n)
now = sapply(results,fun)
answer[t(cc)] = now
answer[t(cc)[,c(2,1)]] = now
answer
}
lapply(list(estimate=function(x)x[['estimate']],
pvalue = function(x)x[['p.v...