R重塑2 'Aggregation function missing: defaulting to length'
R reshape2 'Aggregation function missing: defaulting to length'
我已经在 SO 上多次看到这个 reshape2,但还没有找到解决我的特定问题的方法;
我有这样的数据集;
head(data)
student test score
Adam Exam1 80
Adam Exam2 90
John Exam1 70
John Exam2 60
我正在尝试将其转换为如下所示的宽格式;
Student Exam1 Exam2 ........ ExamX
Adam 80 90
John 70 60
正在使用;
dcast(data,student~test,value.var='score')
但数据最终看起来像这样;
Student Exam1 Exam2
Adam 0 0
John 0 1
有这个错误;
Aggregation function missing: defaulting to length
为什么要将所有这些值更改为(0 或 1)?
感谢@akrun 指出。
嗯,您的数据很可能有重复的行,看起来像这样:
student test score
Adam Exam1 80
Adam Exam1 85
Adam Exam2 90
John Exam1 70
John Exam2 60
或者像这样:
student class test score
Adam Biology Exam1 80
Adam Theology Exam1 85
Adam Theology Exam2 90
John Biology Exam1 70
John Theology Exam2 60
当你这样施法时:dcast(data, student + class ~ test, value.var='score')
我已经在 SO 上多次看到这个 reshape2,但还没有找到解决我的特定问题的方法;
我有这样的数据集;
head(data)
student test score
Adam Exam1 80
Adam Exam2 90
John Exam1 70
John Exam2 60
我正在尝试将其转换为如下所示的宽格式;
Student Exam1 Exam2 ........ ExamX
Adam 80 90
John 70 60
正在使用;
dcast(data,student~test,value.var='score')
但数据最终看起来像这样;
Student Exam1 Exam2
Adam 0 0
John 0 1
有这个错误;
Aggregation function missing: defaulting to length
为什么要将所有这些值更改为(0 或 1)?
感谢@akrun 指出。
嗯,您的数据很可能有重复的行,看起来像这样:
student test score
Adam Exam1 80
Adam Exam1 85
Adam Exam2 90
John Exam1 70
John Exam2 60
或者像这样:
student class test score
Adam Biology Exam1 80
Adam Theology Exam1 85
Adam Theology Exam2 90
John Biology Exam1 70
John Theology Exam2 60
当你这样施法时:dcast(data, student + class ~ test, value.var='score')