我有以下数据框的小部分,我试图转换为矩阵:
my.df <- data.frame(person = c('A', 'A', 'B', 'B', 'B', 'C'),
week = c(1, 2, 1, 3, 3, 2),
event = c('visit', 'buy', 'visit', 'visit', 'buy', 'visit'))
> my.df
person week event
1 A 1 visit
2 A 2 buy
3 B 1 visit
4 B 3 visit
5 B 3 buy
6 C 2 visit
我尝试使用在完整数据框上应用的以下命令来执行此操作:
library(reshap2)
acast(my.df, person ~ week, function(x) {sort(as.character(x))[1]},
value.var = 'event', fill = 'none')
但是,我收到以下错误:
Error in unique.default(x) :
long vectors not supported yet: memory.c:1125
我认为这与我的大数据集有关。有人能告诉我如何克服这样的问题?