Accessing column with df[col] gives: Error 'x' must be atomic for 'sort.list'

I have a very simple array on which I want to run ROC curve analysis. But first, when i try to force data into Factor type using command table[1]<-factor(table[1]), i get the error

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

Few sample rows from the data are give below

GRADE   TRUE-GRADE

benign  Benign
benign  Benign
benign  Benign
benign  Benign
benign  Benign
benign  Benign
benign  Malignant
benign  Malignant
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Benign
indeterminate   Malignant
indeterminate   Malignant
indeterminate   Malignant
likely benign   Benign
likely benign   Benign
likely benign   Benign

Can someone tell me what I am doing wrong ? result of str(table) is given below:

data.frame':   127 obs. of  2 variables:
 $ GRADE        : Factor w/ 5 levels "benign","indeterminate",..: 1 1 1 1 1 1 1 1 1 

 $ BENIGN.MALIGN: Factor w/ 2 levels "Benign","Malignant": 1 1 1 1 1 1 1 1 1 1 ...

Answers


The function [ applied to a data frame returns a data frame (if only one argument is used). If you want to access a single column and return it as a vector, you have to use [[ instead.

table[1] <- factor(table[[1]])

But this may not be necessary since both columns are factors (see your str output).

By the way: table is not a good name for an object, since it's also the name of a basic R function.


Need Your Help

How do I layout nested RecyclerViews, while remaining performant?

android performance android-layout android-recyclerview

I am trying to achieve something similar to Google Play Music's "Listen Now" layout. Every example I have found on the web is a single, simple RecyclerView. I am trying to achieve something much more

If strings are immutable in .NET, then why does Substring take O(n) time?

c# .net string substring time-complexity

Given that strings are immutable in .NET, I'm wondering why they have been designed such that string.Substring() takes O(substring.Length) time, instead of O(1)?