r – Error: x must be atomic for sort.list

r – Error: x must be atomic for sort.list

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.

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

r – Error: x must be atomic for sort.list

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)

Leave a Reply

Your email address will not be published.