如何显示两列与相应日期的交集?

how to display the intersect of two columns with the corresponding date?

三列分别是日期、第二页和退出页。 我想在 secondpage 列和 exitpage 列中显示通用值以及相应的日期。

我使用了相交(col1,col2)
但我也想显示日期。

日期------------第二页------------ --退出页面
27/09--------首页----------------首页
28/09------------着陆页----------------首页
29/09------------联系我们--------------------关于我们
30/09------------关于我们------------------------关于我们

我需要输出为

日期------------第二页------------ - 退出页面
27/09--------首页----------------首页
30/09------------关于我们-------------------- 关于我们

这是一个使用data.table

的解决方案

我已经先生成了示例数据

dt<-data.table("date" = c("27/09","28/09","29/09","30/09"),
               "secondpage" = c("homepage","landingpage","contactus","aboutus"),
               "exitpage" = c("homepage","homepage","aboutus","aboutus"))

> dt
    date  secondpage exitpage
1: 27/09    homepage homepage
2: 28/09 landingpage homepage
3: 29/09   contactus  aboutus
4: 30/09     aboutus  aboutus

下面的代码应该会给你想要的输出

dt_res<-dt[secondpage == exitpage]

> dt_res
    date secondpage exitpage
1: 27/09   homepage homepage
2: 30/09    aboutus  aboutus

不使用数据 table 的替代方案是

dt_res<-dt[dt$secondpage == dt$exitpage,]

希望对您有所帮助