r - 错误 : x must be atomic for 'sort.list'

标签 r

这很奇怪。我收到这个错误

Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?



当我在列表上执行此代码时
 cc3 <- as.data.frame(table(cc2))

可能有什么问题?

这是列表的头部。
head(cc2)   
V1
1:    174
2:    174
3:    211
4: 177106
5: 177106
6: 177106 

编辑:
当我运行时,str(cc2)我明白了
Classes ‘data.table’ and 'data.frame':  149706 obs. of  1 variable:
$ V1:List of 149706
..$ : Named chr "174"
.. ..- attr(*, "names")= chr "V11"
..$ : Named chr "174"
 .. ..- attr(*, "names")= chr "V7"
 ..$ : Named chr "211"
  .. ..- attr(*, "names")= chr "V6"
 .. [list output truncated]
 - attr(*, ".internal.selfref")=<externalptr> 

最佳答案

来自 str(cc2) 的输出,data.table 中的变量 V1 本身就是一个列表。这意味着 cc2 是一个长度为 1 的嵌套列表。发生错误是因为 table电话sort.list ,这需要一个原子向量作为输入。

尝试使用 unlist :

cc3 <- as.data.frame(table(unlist(cc2)))
unlist将(递归地)从它们的列表容器中提取元素。所以unlist(cc2)将返回一个向量,它直接与 table 一起使用.

关于r - 错误 : x must be atomic for 'sort.list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36582505/

相关文章:

r - 如何根据其他变量创建新的序数变量?

r - 在 r markdown html 中中断之前打印更多列

r - 在 R bookdown 中如何设置默认代码输出背景颜色

R - Rselenium - 使用 = 'id' 导航下拉菜单/列表/框

r - 在facet_wrap的某些面板上的geom_rect

R ethogram 或 actogram 脚本

r - 用ggplot2绘制SpatialLinesDataFrame

在 R 中删除 spplot 上的色标?

sqlite - UNIX 将大型 csv 导入 SQLite

r - 如何: A scenebreak in bookdown