简体   繁体   English

如何将一列从一个文件子集到另一文件的同一列?

[英]How to subset a column from one file to the same column in another file?

I have two different .csv files. 我有两个不同的.csv文件。 One of the files, let's call it CA, has a set of dates and times in one column (structured as: mm/dd/yyyy hh:mm:ss ). 其中一个文件(称为CA)在一个列中具有一组日期和时间(结构为: mm/dd/yyyy hh:mm:ss )。 I have another .csv file, let's call is CA_adjusted, that has a column structured in the same manner. 我还有另一个.csv文件,我们称其为CA_adjusted,该文件具有以相同方式构造的列。

I want to subset CA_adjusted with the dates and times of CA, so that I can pull out all relevant data in CA_adjusted. 我想用CA的日期和时间对CA_adjusted进行子集设置,以便可以提取CA_adjusted中的所有相关数据。 I would, preferably, like to subset that Date and Time column itself from CA to the Date and Time column in CA_adjusted. 我希望,最好将“日期和时间”列本身从CA子集化为CA_adjusted中的“日期和时间”列。 How do I do this? 我该怎么做呢?

I must admit I'm not 100% clear what type of join you need, because these things are hard to describe! 我必须承认,我不是100%清楚您需要哪种类型的联接,因为这些事情很难描述! But, I think a semi_join will do what you want. 但是,我认为semi_join您的需求。 It will return the table you specify with matching cases in another table. 它将返回您指定的表,并在另一个表中匹配大小写。 An example: 一个例子:

install.packages("dplyr")
require("dplyr")

set.seed(0)
x <- sample(1:100, 100, replace = TRUE)
x <- data.frame(x)
y <- sample(1:100, 100, replace = TRUE)
y <- data.frame(y)
y$x <- y$y         # so dplyr knows which columns to join on
which(x$x == y$y)

a <- semi_join(x, y)  # returns table x with matching rows in y

Check out the other join options in dplyr if this isn't exactly what you want: 退房的其他join在dplyr选择,如果这不是你想要的东西:

?dplyr::join

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从与另一个共享同一列的数据集中传输列 - How to transfer a column from a dataset sharing the same one with another one 如何将一个CSV文件中的列值附加到文件中某个点的另一个值 - how to Append column value from one CSV file to another from a certain point in the file 如何从另一个文件中的列创建列表? - How to create a list from a column in another file? 需要使用另一个文件上的列信息对主数据框进行子集化 - Need to subset the main dataframe using the column information on another file 如何按一列将数据表子集化,而另一列则最小值 - How to subset a data table by one column with minimal value in another 如何将单列从一个文件合并到另一个文件 - How can I merge a single column from one file to another file R 一列中相同值的子集行依赖于另一列中的多个值 - R subset rows of same value in one column dependent on multiple values in another column 子集在一列中具有相同值的所有行,按另一列分组,其中第三列的至少一行包含 R 中的特定字母 - subset all rows with the same value in one column, grouped by another column, where at least one row of third column contains a specific letter in R 在 Shiny 中动态加载文件和子集数据(任何列) - Dynamically load a file and subset data from it (any column) in Shiny 从 csv 文件中读取列名并子集 dataframe - Read column names from a csv file and subset a dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM