Mae*_*orm 22 indexing syntax r vector dataframe
我有一个非常简单的数组,我想在其上运行ROC曲线分析.但首先,当我尝试使用命令将数据强制转换为因子类型时table[1]<-factor(table[1]),我得到了错误
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
Run Code Online (Sandbox Code Playgroud)
下面给出了数据中很少的样本行
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
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我做错了什么吗?str(表)的结果如下:
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 ...
Run Code Online (Sandbox Code Playgroud)
Sve*_*ein 31
[应用于数据帧的函数返回数据帧(如果仅使用一个参数).如果要访问单个列并将其作为向量返回,则必须使用[[.
table[1] <- factor(table[[1]])
Run Code Online (Sandbox Code Playgroud)
但这可能没有必要,因为两列都是因子(参见str输出).
顺便说一下:table对象不是一个好名字,因为它也是一个基本R函数的名称.