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

前端 未结 3 1891
梦谈多话
梦谈多话 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.

    0 讨论(0)
  • 2020-12-17 17:20

    I solved it by unlisting cc2 unli <- unlist(cc2) then converted it to df df<-as.data.frame(cc2)

    0 讨论(0)
  • 2020-12-17 17:22

    I just needed unlist(myList) for a list I constructed with iterative a list I constructed by index (myList[[i]] <- val) to be able to apply my comparison function of choice (median)

    0 讨论(0)
提交回复
热议问题