0

I have a data frame that looks like the following.

"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 (in reshape2) seems my best bet so far to do this in one line.

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

Though I end up with this;

"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"

Along with the error;

Aggregation function missing: defaulting to length(response)

How can I get that second format without losing my strings in the "response" column?

beatsandbosons
  • 39
  • 1
  • 10

0 Answers0