【发布时间】:2016-07-06 13:00:47
【问题描述】:
我有一个包含客户购买信息的数据集。我试图通过连接 device_id(客户)、store_id、product_id 和 date(购买)来创建唯一 ID。我为此使用了以下代码
customer$device_store_product_date <- paste(customer$device, customer$store_id, customer$product_id, customer$date, sep='_')
结果列是这样的:
device_store_product_date
48c6eec37affa1db_203723_9313962_2016-02-19
eb2c2f00071b97f3_179926_6180944_2016-02-20
d82066a784c9552_180704_9308311_2016-02-20
9766bba65b1ef9ac_204187_9313852_2016-02-20
77d80c1066f5267_180488_9312672_2016-02-20
正如预期的那样,仍然存在重复。为了识别它们,我使用了 duplicated():
x1 = customer[duplicated(customer$device_store_product_date),]
但是,对于少数 x1$device_store_product_date,只有单个条目存在。这不应该是这种情况,因为 x1 应该包含重复的值。让我知道我哪里出错了。要选择与我使用的 device_store_product_date 的特定值相对应的条目:
filter(x1, x1$device_store_product_date=="14163e6b6ed06890_203723_9313477_2016-02-20")
【问题讨论】:
标签: r duplicates concatenation string-concatenation