简体   繁体   English

在“a”列中查找两个不同数据集的“b”列中具有不同值的值

[英]Finding values in a columns “a” which has different values in column “b” for two different data set

Data contains multiple columns and 3000 row数据包含多列和 3000 行

Same OrderNo but different Ordertype .相同的OrderNo但不同Ordertype

I want to get all the OrderNo whose Ordertype are different in the two data frame.我想获取两个数据框中Ordertype不同的所有OrderNo

I have isolated the two columns from the two data frame and set them in ascending order.我已经从两个数据框中分离出两列,并按升序设置它们。 Then I tried to use the function cbind to combine the two columns and find the missing values in one of the columns.然后我尝试使用 function cbind将两列合并并在其中一列中查找缺失值。

xxx <- data.frame( orderNo = c(1:10), Ordertype = c("a", "b", "c", "d", "a", "b", "c", "d", "e", "f"))
yyy <- data.frame( orderNo = c(1:10), Ordertype = c("a", "b", "c", "d", "a", "b", "e", "d", "e", "f"))

In the above example: OrderNo "7" corresponds to "c" in one data frame and "e" in another data frame.在上面的例子中: OrderNo “7”对应一个数据帧中的“c”和另一个数据帧中的“e”。 I want a set of all such number with a different value in the column Ordertype as my output.我想要一组在Ordertype列中具有不同值的所有此类数字作为我的 output。

It sounds like you want a data frame that contains differences between two data frames, matched by (and including) orderNo .听起来您想要一个包含两个数据帧之间差异的数据帧,由(并包括) orderNo Is that correct?那是对的吗?

One possibility is:一种可能性是:

res <- merge(xxx, yyy, by = "orderNo")
res[res[,2] != res[,3], ]

  orderNo Ordertype.x Ordertype.y
7       7           c           e

Using dplyr and anti_join you can do the following to find differences:使用dplyranti_join您可以执行以下操作来查找差异:

library(dplyr)
inner_join(anti_join(xxx, yyy), anti_join(yyy, xxx), by='orderNo')

  orderNo Ordertype.x Ordertype.y
1       7           c           e

暂无
暂无

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

相关问题 查找和检索两列值不同的行 - Finding and retrieving rows for which values of two columns are different R: Add boolean column to a data.table based on return values of a function which evaluates two columns from different data.table - R: Add boolean column to a data.table based on return values of a function which evaluates two columns from different data.table 在一行中查找两个最高值,然后在同一列但不同行中查找值 - Finding two highest value in a row and then values in the same column but different row 查找列中具有不同值的对象的平均值 - Finding mean values of objects with different values in column 结合两个数据框,相似的行,相似的列,除了一列具有不同的值 - Combining two dataframes, similar rows, similar columns except one column has different values 如何比较不同列的不同容差值的两个数据帧? - how to compare two data frames with different tolerance values for different columns? 如何为R中的相同两列子集具有不同值的数据框 - How do you subset a data frame that has different values for the same two columns in R 如何在 R 中创建一个新列来匹配来自两个不同数据框中的多个值 - How to create a new column in R which matches multiple values from two different data frames 如何从 R 中的两个不同数据帧添加两列,其中一列只有另一列的唯一值的子集 - How to add two columns from two different dataframes in R wherein one column just has subset of unique values of the other 在data.table的两个不同列中寻找相同的值 - Looking for same values in two different columns in data.table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM