如何使用两个相关列投射数据框?

时间:2016-09-23 11:36:06

标签: r reshape2 dcast

我的数据框如下所示。

"id" "question" "response"  "suite"
1    "x"        "a"         "1"
2    "y"        "b"         "1"
3    "x"        "c"         "1"
4    "y"        "d"         "1"
5    "x"        "e"         "2"
6    "y"        "f"         "2"
到目前为止,Dcast(在reshape2中)似乎是我最好的选择。

result <- dcast(df, id + suite ~ question, value.var = "response")

虽然我最终得到了这个;

"id" "suite" "x" "y"
1    "1"     "1" "1"
2    "1"     "1" "1"
3    "1"     "1" "1"
4    "1"     "1" "1"
5    "2"     "1" "1"
6    "2"     "1" "1"

随着错误;

Aggregation function missing: defaulting to length(response)

我怎样才能获得第二种格式而不会在&#34;响应中丢失我的字符串&#34;列?

0 个答案:

没有答案