Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较R中的两个表,找出客户不购买的产品_R_Dplyr - Fatal编程技术网

比较R中的两个表,找出客户不购买的产品

比较R中的两个表,找出客户不购买的产品,r,dplyr,R,Dplyr,我有两个表格如下: Cust_list <- data.frame( stringsAsFactors = FALSE, Customer = c("Mike S.","Tim P."), Type = c("Shoes","Socks"), Product_ID = c(233,6546) ) Product_Table <- data.frame( stringsAsFactors = FALSE

我有两个表格如下:

Cust_list <- data.frame(
stringsAsFactors = FALSE,
Customer = c("Mike S.","Tim P."),
Type = c("Shoes","Socks"),
Product_ID = c(233,6546)
)


Product_Table <- data.frame(
stringsAsFactors = FALSE,
Product_ID = c(233,256,296,8536,6546,8946),
Type = c("Shoes","Shoes","Shoes", "Socks","Socks","Socks")
)
Cust_list这是否有效:

library(dplyr)
library(tidyr)
Cust_list %>% full_join(Product_Table) %>% arrange(Type) %>% 
           fill(Customer,.direction = 'down') %>% anti_join(Cust_list)
Joining, by = c("Type", "Product_ID")
Joining, by = c("Customer", "Type", "Product_ID")
  Customer  Type Product_ID
1  Mike S. Shoes        256
2  Mike S. Shoes        296
3   Tim P. Socks       8536
4   Tim P. Socks       8946

你已经试过什么了?
library(dplyr)
library(tidyr)
Cust_list %>% full_join(Product_Table) %>% arrange(Type) %>% 
           fill(Customer,.direction = 'down') %>% anti_join(Cust_list)
Joining, by = c("Type", "Product_ID")
Joining, by = c("Customer", "Type", "Product_ID")
  Customer  Type Product_ID
1  Mike S. Shoes        256
2  Mike S. Shoes        296
3   Tim P. Socks       8536
4   Tim P. Socks       8946