【问题标题】:R generate an simple integer matrix with defined number of row and columnR生成具有定义的行数和列数的简单整数矩阵
【发布时间】:2013-05-30 17:34:18
【问题描述】:

如何生成一个整数随机矩阵,其值来自 r 中的 {1 ... 15},例如 9 行 100 列?

(我的问题可能很基本,但由于未知原因我找不到解决方案)

【问题讨论】:

    标签: r random matrix integer


    【解决方案1】:
    matrix(sample.int(15, size = 9*100, replace = TRUE), nrow = 9, ncol = 100)
    

    或更简洁的版本

    matrix(sample.int(15, 9*100, TRUE), 9, 100)
    

    但如果你真的想要最少的字符数(我不推荐):

    matrix(sample(15,900,T),9)
    

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 1970-01-01
      • 2014-10-24
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 2012-10-16
      • 2018-05-23
      • 1970-01-01
      相关资源
      最近更新 更多