[英]How to take multiple Sample() vector outputs and combine them into a data frame
sorry if this is a somewhat basic question.抱歉,如果这是一个基本的问题。 But I am wanting to take a random sample sample of data from each day (coming from separate files), using the sample() function, and then combine each of those sampled rows from the day data and combine it all into a week data frame of only my sampled data from the day datasets.但是我想使用 sample() function 从每天(来自单独的文件)中随机抽取数据样本,然后将这些采样行中的每一行从日数据中组合起来,并将其全部组合成一周的数据框仅来自当天数据集的采样数据。
Assume that the data is held in files name for their day, like mydata_2020_05_17.csv假设数据保存在当天的文件名中,例如mydata_2020_05_17.csv
library(tidyverse)
readDay <- function(date, dir, sampleN){
path <- paste0(dir, "/", "mydata_", date, ".csv")
read_csv(path) %>%
as_tibble() %>%
# You many not need this if the records already have the date
mutate(DATE = date) %>%
sample_n(sampleN, replace = FALSE)
}
Lets start on the first Sunday of the month让我们从每月的第一个星期日开始
answerWeek = map_df(seq.Date(from = as_date("2020-05-03"), length.out = 6, by = 1),
~ readDay(.x, "~/nefarious/data", sampleN = 20))
NOT RUN because I don't have a folder full of dated csv data.不运行,因为我没有一个装满过时 csv 数据的文件夹。
Let us know if I've mis-interpreted what you're looking for.如果我误解了您要查找的内容,请告诉我们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.