'Sample rows of a list of matrices based on numbers from another list
I have a list of matrices from which I want to randomly draw rows based on the numbers of another list. Here is the list of matrices:
x <- list(`1` = matrix(1:20, nrow=10), `2` = matrix(1:20, nrow=10))
Here is the list of numbers
y <- list(`1` = 2, `2` = 3) #for `1` I want to draw 2 rows and for `2` I want to draw 3 rows
The final list will look like this:
$`1`
[,1] [,2]
[1,] 1 11
[2,] 6 16
$`1`
[,1] [,2]
[1,] 1 11
[2,] 7 17
[3,] 9 19
How to achieve this in base R? Thanks for any help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
