How can I take a sample of n random points from a matrix filled with 1 and 0?
a=rep(0:1,5) b=rep(0,10) c=rep(1,10) dataset=matrix(cbind(a,b,c),nrow=10,ncol=3) dataset [,1] [,2] [,3] [1,] 0 0 1 [2,] 1 0 1 [3,] 0 0 1 [4,] 1 0 1 [5,] 0 0 1 [6,] 1 0 1 [7,] 0 0 1 [8,] 1 0 1 [9,] 0 0 1 [10,] 1 0 1
I want to be sure that the positions (row, col) from were taken N samples randomly.
I know sample {base} , but it doesn't seem to allow me to do this, other methods that I know are spatial methods that will make me add x, y and change it to a spatial object and return to the normal matrix again.
Additional Information
By accident, I also mean the distribution inside the "matrix space", for example. if I make a selection of 4 points, I donβt want to have 4 neighboring points as a result, I want them to be distributed in the βmatrix spaceβ.
Knowing the position (row, column) in the matrix where I selected random points would also be important.
r random-sample
Gago-silva
source share