【问题标题】:Why are these two matrixes not concatenating properly为什么这两个矩阵不能正确连接
【发布时间】:2020-07-16 18:43:12
【问题描述】:

我有两个矩阵: theoretical_meansampleMean

我正在尝试将它们合并到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.

【问题讨论】:

  • 你能展示一个可重现的例子吗
  • 这里,输出太长,但是这个链接在这里。 imgur.com/a/ySlJPtP。第一张图片是我得到的,第二张图片是我喜欢的样子。它不断重复第一个块 7 次
  • 希望能帮助解释一下
  • 有图片,我无法测试。你可以使用dput
  • 对不起,我不知道怎么用dput

标签: r list dataframe matrix mean


【解决方案1】:

您应该能够查看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" 

运行此代码并打印出samMeansamVar 以查看正确的配对组合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 2022-12-13
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    相关资源
    最近更新 更多