R:如何生成每个块的样本?

时间:2018-05-02 09:24:10

标签: r sample

我有一个h = 30个变量(列数)的数据,其中b = 3个块(每个块中有10个变量) 我想根据块数b1生成 size =(h1 / b1)每块的样本。

例如,如果h1 = 8且b1 = 2,我希望每个块 h1 / b1 = 4变量

[1] 2,5,8,10,  11,12,14,17 #4 variable in the 1 block and 4 variable in the 2 block

#or

[1] 2,5,8,10 #4 variable in the 1 block
[2] 1,2,4,7 #4 variable in the 2 block

我试过了:

sample(x = 1:h, size = (h1/b1), replace = FALSE)
[1]  7 15  6 23
#or
sample(x = 1:(h/b), size = (h1/b1), replace = FALSE)
[1] 4 1 2 3

1 个答案:

答案 0 :(得分:0)

试试这个解决方案:

getBook(number): Observable<any>{
    const url = `${this.url}/api/book/`+number+`/edit`;
    return this.http.get(url,{headers: new HttpHeaders({Authorization:'Bearer '+ this.token})});
}

console.log(this.books_edit_data);