我从未真正使用过dplyr,并想知道如何在以下上下文中使用它。所以,我有两个数据框:
trainData <- read.csv("train.csv", header = TRUE, stringsAsFactors = FALSE)
subscriptionData <- read.csv("subscriptions.csv", header = TRUE, stringsAsFactors = FALSE)
> head(trainData)
account.id total
1 001i000000NuOGY 0
2 001i000000NuS8r 0
3 001i000000NuPGw 0
4 001i000000NuO7a 0
5 001i000000NuQ2f 0
6 001i000000NuOQz 0
> head(subscriptionData)
account.id season package no.seats location section price.level total multiple.subs
1 001i000000LhyR3 2009-2010 Quartet 2 San Francisco Premium Orchestra 1 1.0 no
2 001i000000NuOeY 2000-2001 Full 2 San Francisco Orchestra 2 2.0 no
3 001i000000NuNvb 2001-2002 Full 2 Berkeley Saturday Balcony Front 3 2.0 no
4 001i000000NuOIz 1993-1994 Quartet 1 Contra Costa Orchestra 2 0.5 no
5 001i000000NuNVE 1998-1999 Full 2 Berkeley Sunday Balcony Rear 4 2.0 no
现在,我想根据subscriptionData
的{{1}}获取account.id
的子集。我基本上希望将trainData
的子集与subscriptionData
中的account.id
一起使用。
我知道这是一个非常基本的问题,但我是全新的dplyr并且毫无头绪。
答案 0 :(得分:4)
你想要一个半连接:
subscriptionData %>% semi_join(trainData, by = "account.id")