條件的兩個矩陣我有兩個矩陣:old1和GL1,我想從兩個矩陣中的值分配成另一種兩個新的矩陣。我用了這個方法:1)把這兩個矩陣聯繫起來; 2)使用樣本函數隨機分配值; 3)將大矩陣分成兩個新矩陣。下面是代碼:隨機分配值基於R中
library(ms.sev)
### old Global MSSS matrix
data(oldMsss)
old <- data.matrix(oldMsss)
old1 <- old[-1,-1]
## use the global MSSS
data(globalMsss)
gl <- data.matrix(globalMsss)
gl1 <- gl[,-1]
## combine
tc <- rbind(gl1,old1)
set.seed(1)
n.permutations = 5
sum.table = rep(1,n.permutations)
for(j in 1:n.permutations) {
print(j)
t1 <- matrix(sample(tc),nrow=60)
tf <- t1[1:30,]
tf1 <- t1[31:60,]
sum.table[j] <- sum(tf1-tf)
}
通過檢查細節矩陣,我注意到,對於這兩種old1和GL1,從EDSS.0.0到EDSS.9.5,該值應增加(例如,從0.91到10,用於gl1),與y相同,值應該減小(例如,gl1從0.91到0.07)。
然而,我的方法上面是不正確的,因爲它分配值時,沒有采取相關考慮。任何想法如何將值分配給新的矩陣,但遵循類似的模式?
非常感謝......
我聽不太懂你想exactly.If要隨機從兩個分配值是什麼矩陣到另一個矩陣,爲什麼相關性很重要? – Florian
弗洛裏安嗨,遺憾的混亂。我已經刪除了「隨機」一詞。它更像按照上述 – user2669497