Error: x must be atomic for 'sort.list'

前端 未结 3 1900
梦谈多话
梦谈多话 2020-12-17 16:38

This is weird. I get this error

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

3条回答
  •  误落风尘
    2020-12-17 17:07

    From the output of str(cc2), the variable inside of the data.table, V1, is itself a list. This means that cc2 is a nested list of length 1. The error is occurring because table calls sort.list, which requires an atomic vector as input.

    Try using unlist:

    cc3 <- as.data.frame(table(unlist(cc2)))
    

    unlist will (recursively) extract elements from their list containers. So unlist(cc2) will return a vector, which works directly with table.

提交回复
热议问题