我有两个矩阵:
theoretical_mean
和sampleMean
我正在尝试将两者合并为theor_sample_mean
,第一个值theoretical_mean
由连字符连字符分隔,第一个值为sampleMean
。这是我的代码:
sampleMean <- as.data.frame(matrix(unlist(sampleMean),nrow = 7, ncol = 7, byrow = T))
sampleMean <- round(sampleMean,digits = 3)
sampleMean
sampleVar <-lapply(lyst, var)
sampleVar <- as.data.frame(matrix(unlist(sampleVar),nrow = 7, ncol = 7, byrow = T))
sampleVar <- round(sampleVar,digits = 3)
sampleVar
theor_sample_mean <- matrix(paste(theoretical_mean, sampleMean, sep=" - "),nrow=7,dimnames = dimnames(theoretical_var))
theor_sample_var <- matrix(paste(theoretical_var, sampleVar, sep=" - "),nrow=7,dimnames= dimnames(theoretical_var))
theor_sample_mean
Thank you very much.
答案 0 :(得分:0)
您应该能够找到dput
的手册页并弄清楚如何使用它。这是一些编造的数据。如果不需要,不要将其转换为数据帧。
set.seed(42)
samMean <- matrix(sample.int(100, 16), 4, 4, byrow=TRUE)
samVar <- matrix(sample.int(100, 16), 4, 4, byrow=TRUE)
matrix(paste(samMean, "-", samVar), 4, 4)
# [,1] [,2] [,3] [,4]
# [1,] "49 - 36" "65 - 95" "25 - 5" "74 - 84"
# [2,] "18 - 34" "100 - 92" "47 - 3" "24 - 58"
# [3,] "71 - 42" "89 - 24" "37 - 30" "20 - 43"
# [4,] "26 - 15" "3 - 22" "41 - 93" "27 - 8"
运行以下代码并打印出samMean
和samVar
,以查看正确的配对正在组合。