0
votes

Data contains multiple columns and 3000 row

Same OrderNo but different Ordertype.

I want to get all the OrderNo whose Ordertype are different in the two data frame.

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.

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. I want a set of all such number with a different value in the column Ordertype as my output.

1
In both dataframes OrderNo "8" corresponds to "d". Are you sure you have given enough information for us to try to help you?Vitali Avagyan
Yes, I really need help. I have made the changes. Sorry for inconvenience.Aashay Mehta
xxx$orderNo[xxx$Ordertype != yyy$orderType]?jdobres
which(xxx$Ordertype != yyy$Ordertype)Ritchie Sacramento
How can I get a data frame which gives me three columns - "xxx$OrderNo" "xxx$Ordertype" "yyy$Ordertype" ?Aashay Mehta

1 Answers

0
votes

It sounds like you want a data frame that contains differences between two data frames, matched by (and including) 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:

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

  orderNo Ordertype.x Ordertype.y
1       7           c           e