cast()产生意外结果

| 我正在尝试使用Reshape库中的
cast()
投射数据,但是得到了意外的结果。我从其中包含大量数据的数据帧开始,然后返回
all_ia[all_ia$Student.ID == 102050,]
66     102050        1      Mar
67     102050        0      Dec
68     102050        1      May
69     102050        0      Feb
其中变量分别是Student.ID,Profiency.Level和testmonth。 9月的第5个月有一些Student.ID。 当我运行
all_ia.cast <- cast(all_ia, Student.ID ~ testmonth, value=c(\"Proficiency.Level\"), fill=c(\"NA\"))
然后运行
all_ia.cast[all_ia.cast$Student.ID == 102050,]
时,得到了意外的结果:
1325    102050    1    1    1    1    NA
其中的变量分别是Student.ID,12月,2月,3月,5月,9月。当我运行
cast()
时显示警告,
Aggregation requires fun.aggregate: length used as default
。 我的问题是,为什么需要fun.aggregate?为什么强制转换中的Dec和Feb变量等于1而不是0? 谢谢您的帮助!     
已邀请:
        这是因为转换公式
Student.Id ~ tesmonth
并未包含data.frame中的所有变量,即variables9ѭ不包括在内。 通常,这意味着强制转换必须执行聚合,并且聚合公式默认为“ 10”。 您似乎有一个特例,每个学生的月度和熟练程度之间存在一对一的关系。因此,您应该选择一个保留数据的聚合函数,例如服用
mean
,以下方法应起作用:
cast(all_ia, Student.ID ~ testmonth, value=mean(\"Proficiency.Level\"))
您不提供测试数据,因此未经测试。     

要回复问题请先登录注册