R 使用坐标对网格进行随机采样
我有一个编号网格19 x 22放置在一个图像上,我需要随机选择418帧中的250帧。有没有一种方法可以做到这一点,随机选择一个x和y坐标,而没有任何重复 谢谢R 使用坐标对网格进行随机采样,r,R,我有一个编号网格19 x 22放置在一个图像上,我需要随机选择418帧中的250帧。有没有一种方法可以做到这一点,随机选择一个x和y坐标,而没有任何重复 谢谢 这里有一种快速而肮脏的方法,可以生成随机的X和Y值,而无需在网格中重复 library(tidyverse) # Gives us both %>% and filter_n # Create a dataframe (technically a tibble) with one cell for each # cell in y
这里有一种快速而肮脏的方法,可以生成随机的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)
如果您发布了要采样的数据类型的代码示例,我可能可以简化。您的网格是矩阵吗?请提供一个数据集示例。您可以在此处了解有关创建示例的更多信息: