这很奇怪。我收到这个错误
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/