来自矩阵的样本以及R中的分割采样值和非采样值

时间:2018-06-14 16:04:29

标签: r matrix random

我想抽样' n'矩阵中的行:

    import { LOCALE_ID } from '@angular/core';

constructor(private modalService: BsModalService) {
  console.log("LOCALE_ID", LOCALE_ID);
}

我使用以下代码:

data <- matrix(data = 1:12, nrow = 4, ncol = 3)

     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12

有没有办法可以返回一个只包含未经过采样的行的矩阵?在这种情况下:

selection <-sample(nrow(data),size = 2, replace = FALSE)
data[selection,]

     [,1] [,2] [,3]
[1,]    4    8   12
[2,]    3    7   11

非常感谢提前。

0 个答案:

没有答案