R:强制转换的错误消息“‘listgreater’中未实现的类型‘list’”

Sal*_*lly 4 casting r

使用以下命令(x 是一个包含 3 列 A、B 和 C 的表)

library(reshape)
cast(x, A~B)
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

Using C as value column.  Use the value argument to cast to override this choice
Error in order(A = list("xxx",  : 
  unimplemented type 'list' in 'listgreater'
Run Code Online (Sandbox Code Playgroud)

这意味着什么以及如何解决?


我想这可能是由于数据框的数据格式造成的(如果我错了,请纠正我)。正如我使用 str 命令测试了表 x 和 y 的格式。

str(x) returns
$ A: List of 6
..$ : chr "xxx"
....
$ B:chr "yyy" "yy2" ....
...
$ C: List of 6
..$ : num 22.....
...
Run Code Online (Sandbox Code Playgroud)

对于另一个具有 DE 和 F 列的表 y,当我运行cast 命令时没有出现错误消息。

str(y) shows that all D E F columns are Factor w/ 6 levels....
Run Code Online (Sandbox Code Playgroud)

如何使包含数据框 x 的 list 和 num 的强制转换工作?

Oha*_*dok 8

使用

df <- as.data.frame(lapply(df, unlist))
Run Code Online (Sandbox Code Playgroud)