简体   繁体   English

如何获取多个 Sample() 向量输出并将它们组合成一个数据框

[英]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.

相关问题 如何在r的单个数据帧中组合输出? - How to combine the outputs in a single data frame in r? 如何在向量的情况下将结果组合为数据帧 - how to combine the result as a data frame in case of vector 如何从 R 数据帧的两列中联合采样? - How to take sample from two columns of R data frame jointly? 如何使用每个向量的元素名称(在R中)将多个向量组合到一个数据帧中 - how to combine multiple vectors into a data frame using the names of the elements of each vector (in R) R如何使用矢量作为采样大小对data.frame列表进行采样 - R How to sample a list of data.frame, with vector as sampling size 如何在 R 中组合多个数据框列 - How to combine multiple data frame columns in R 我如何从一个数据框中获取每24列并将其添加到另一个数据框的底部? - How can I take every 24 columns from a data frame and add them to the bottom of another data frame? 从多个数据框的列表中提取特定的列,并将它们组合成r中的新数据框 - extracting particular column from a list of multiple data frames and combine them into a new data frame in r 如何将多个数据csv文件合并到单个数据帧中? - How to combine multiple data csv files in to single data frame? 如何组合列的成员,将它们收集在数据框中并给它们一个新名称,在 R 中? - How to combine member of a column, collect them in a data frame and give them a new name, in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM