我要轉換的以下數據集:將列值轉換爲單列的ID
transaction_id productsku
1 SK0001
1 SK0002
2 AB0001
2 AC0001
2 AC0002
3 BC0001
4 BC0002
理想的數據集是:
transaction_id x1 x2 x3
1 SK0001 SK0002
2 AB0001 AC0001 AC0002
3 BC0001
4 BC0002
所以,我用下面的代碼轉換,但它失敗了。基於transation_id
然後獲取productsku
每個組
order <- cast(order_0, transaction_id ~ productsku)
Using productsku as value column. Use the value argument to cast to override this choice
Error in `[.data.frame`(data, , variables, drop = FALSE) :
undefined columns selected