2017-01-12 3 views
0

画像上に番号付きグリッド(19 x 22)があり、無作為に418フレームのうち250個を選択する必要があります。任意の重複を持たずにxとyの座標をランダムに選択してこれを行う方法はありますか?座標を使用して無作為にグリッドをサンプルします

おかげ

Example of grid over image (rows and columns are not labeled)

+0

"グリッド"はマトリックスですか? –

+0

あなたのデータセットの例を提供してください。ここでサンプルを作成する方法の詳細は、http://stackoverflow.com/help/mcveを参照してください。 –

答えて

0

ここにあなたのグリッドにある繰り返しなしでランダムにXとYの値を生成する迅速かつ汚い方法です。

library(tidyverse) # Gives us both %>% and filter_n 

# Create a dataframe (technically a tibble) with one cell for each 
# cell in your grid 
combos <- expand.grid(x = seq(1, 19, 1), y = seq(1, 22, 1)) %>% 
    tbl_df() 

# Draw 250 random samples from the data without replacement 
# If you post more information about the data you're using, 
# I might be able to skip the creation of the combos data entirely 
grid_sample <- sample_n(combos, size = 250, replace = FALSE) 

サンプルしたいデータタイプのコード例を投稿すると、私は単純化することができます。

関連する問題