R reshape2 'Aggregation function missing: defaulting to length'

chattrat423

I have seen this reshape2 several times on SO but haven't seen a solution to my particular problem;

I have a dataset like this;

head(data)
student    test    score
Adam      Exam1     80
Adam      Exam2     90
John      Exam1     70
John      Exam2     60

I am trying to cast this to a wide format that looks like this;

Student    Exam1    Exam2 ........ ExamX
Adam         80       90
John         70       60

using;

dcast(data,student~test,value.var='score')

but the data ends up looking like something like this;

Student    Exam1     Exam2
Adam        0          0
John        0          1

with this error;

Aggregation function missing: defaulting to length

Any ideas why it is changing all of these values to a (0 or 1)?

JelenaČuklina

Thanks to @akrun who pointed it out.

Well, there's a high chance that your data has duplicate row that look either like this:

student    test    score
Adam      Exam1     80
Adam      Exam1     85
Adam      Exam2     90
John      Exam1     70
John      Exam2     60

Or like this:

student   class     test    score
Adam      Biology   Exam1     80
Adam      Theology  Exam1     85
Adam      Theology  Exam2     90
John      Biology   Exam1     70
John      Theology  Exam2     60

When you cast it like this: dcast(data, student + class ~ test, value.var='score')

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

R:プロット用にtidyverseをdplyr / reshape2に変換

分類Dev

SumifとRでのピボット(reshape2、melt、cast、merge ..)

分類Dev

R reshape2 dcast:データを変換します

分類Dev

Rは複数の条件に基づいて行を取得します-dplyrとreshape2を使用します

分類Dev

R reshape2 '集計関数がありません:デフォルトで長さ'

分類Dev

R:reshape2を使用してデータフレームを長いデータ形式に再形成します

分類Dev

Rでのデータフレームの操作:おそらくdplyrとreshape2を使用する

分類Dev

R-一意の行にデータフレームをキャストします-reshape2

分類Dev

Defaulting an Angular2 <option> in a <select> with two-way binding

分類Dev

R timeseries - identify missing observations (timestamps) and insert NAs to create time series of given length

分類Dev

R Reshape2を使用して、reshape(統計パッケージ関数)が設計された目的を実行します

分類Dev

tidyr VS dplyr + reshape2

分類Dev

Writing sql without aggregation function

分類Dev

Rの場合:tidyrとreshape2を使用して列を分割することにより、複数の行を取得します

分類Dev

MongoDB Aggregation - Possible to have an OR operator in a group function?

分類Dev

R & XML2: Replace missing XML elements with NA

分類Dev

Impute missing observations R

分類Dev

Missing :endfunction error for vim function

分類Dev

detectMultiScale function missing in opencv 3

分類Dev

spark window function missing values

分類Dev

ppf function missing from t

分類Dev

ggplot2、reshape2、およびHmiscを使用してRで三角形ヒートマップを実行するにはどうすればよいですか?

分類Dev

defaulting unmatched backrefrences in perl or sed

分類Dev

Generalized type-defaulting rules

分類Dev

SQL Pivot with dynamic generated columns, aggregate function and columns without aggregation

分類Dev

Combine complex aggregation function when using pandas groupby

分類Dev

NodeJS, MongoDB, Aggregation function with $lookup result is empty array []

分類Dev

How to pass an array to an User Defined Aggregation Function in Spark (UDAF)

分類Dev

Excel Aggregation function on arithmetic combinations without temporary column?

Related 関連記事

  1. 1

    R:プロット用にtidyverseをdplyr / reshape2に変換

  2. 2

    SumifとRでのピボット(reshape2、melt、cast、merge ..)

  3. 3

    R reshape2 dcast:データを変換します

  4. 4

    Rは複数の条件に基づいて行を取得します-dplyrとreshape2を使用します

  5. 5

    R reshape2 '集計関数がありません:デフォルトで長さ'

  6. 6

    R:reshape2を使用してデータフレームを長いデータ形式に再形成します

  7. 7

    Rでのデータフレームの操作:おそらくdplyrとreshape2を使用する

  8. 8

    R-一意の行にデータフレームをキャストします-reshape2

  9. 9

    Defaulting an Angular2 <option> in a <select> with two-way binding

  10. 10

    R timeseries - identify missing observations (timestamps) and insert NAs to create time series of given length

  11. 11

    R Reshape2を使用して、reshape(統計パッケージ関数)が設計された目的を実行します

  12. 12

    tidyr VS dplyr + reshape2

  13. 13

    Writing sql without aggregation function

  14. 14

    Rの場合:tidyrとreshape2を使用して列を分割することにより、複数の行を取得します

  15. 15

    MongoDB Aggregation - Possible to have an OR operator in a group function?

  16. 16

    R & XML2: Replace missing XML elements with NA

  17. 17

    Impute missing observations R

  18. 18

    Missing :endfunction error for vim function

  19. 19

    detectMultiScale function missing in opencv 3

  20. 20

    spark window function missing values

  21. 21

    ppf function missing from t

  22. 22

    ggplot2、reshape2、およびHmiscを使用してRで三角形ヒートマップを実行するにはどうすればよいですか?

  23. 23

    defaulting unmatched backrefrences in perl or sed

  24. 24

    Generalized type-defaulting rules

  25. 25

    SQL Pivot with dynamic generated columns, aggregate function and columns without aggregation

  26. 26

    Combine complex aggregation function when using pandas groupby

  27. 27

    NodeJS, MongoDB, Aggregation function with $lookup result is empty array []

  28. 28

    How to pass an array to an User Defined Aggregation Function in Spark (UDAF)

  29. 29

    Excel Aggregation function on arithmetic combinations without temporary column?

ホットタグ

アーカイブ