你怎么解决“数字”)):当你有分类数据而不是数字时,在FactoMineR MCA中'哪个'不是逻辑“错误信息的参数?

时间:2016-12-16 22:59:11

标签: r

我正在尝试使用FactoMineR在数据集上运行MCA,并且尽管我的数据是Y / N(即非数字二进制1/0),仍然会收到此错误:

错误(unlist(lapply(listModa,is.numeric))):'哪个'不合逻辑的参数

我已经读过R分类数据与因子类型有关,所以即使你有字符也可以得到这个错误。但我不知道“因素类型”的含义,或者我如何改变它。我一直在尝试使用这段代码:

require(FactoMineR)
head(mydata)
cats = apply(mydata, 2, function(x) nlevels(as.factor(x)))
mca1 = MCA(mydata, graph = FALSE)

我是一个完整的R新手并且不了解很多编码语言但是真的想学习!任何帮助将非常感谢,因为这是一个硕士项目

> dput(head(mydata))
structure(list(Icthyosaur = c("Y", "Y", "N", "N", "Y", "N"), 
Plesiosaur = c("N", "N", "Y", "N", "N", "N"), Pliosaur = c("N", 
"N", "N", "Y", "N", "N"), Crocodile = c("N", "N", "N", "N", 
"N", "Y"), `Bite mark` = c("Y", "Y", "N", "N", "Y", "Y"), 
`Mechanical stress` = c("N", "N", "Y", "N", "N", "N"), `Erosive arthrosis` = c("N", 
"N", "N", "Y", "N", "N"), Fracture = c("N", "N", "N", "N", 
"N", "N"), Exostoses = c("N", "N", "N", "N", "N", "N"), `Vertebral Fusion ` = c("N", 
"N", "N", "N", "N", "N"), Cranial = c("Y", "N", "N", "Y", 
"N", "Y"), Appendicular = c("N", "Y", "N", "N", "N", "N"), 
Axial = c("N", "N", "Y", "N", "Y", "N"), Pelvic = c("N", 
"N", "N", "N", "N", "N"), Pectoral = c("N", "N", "N", "N", 
"N", "N")), .Names = c("Icthyosaur", "Plesiosaur", "Pliosaur", 
"Crocodile", "Bite mark", "Mechanical stress", "Erosive arthrosis", 
"Fracture", "Exostoses", "Vertebral Fusion ", "Cranial", "Appendicular", 
"Axial", "Pelvic", "Pectoral"), call = "XLGetRange(file = \"C:\\\\Users\\\\Ally\\\\Documents\\\\MSci Project\\\\ImportR.xlsx\", sheet = \"Sheet1\",\n     range = c(\"A1:O124\"),\n     as.data.frame = TRUE, header = TRUE, stringsAsFactors = FALSE)", row.names = c(NA, 
6L), class = "data.frame")

> mca1 = MCA(mydata, graph = FALSE)
Error in which(unlist(lapply(listModa, is.numeric))) : 
  argument to 'which' is not logical

> traceback()
3: which(unlist(lapply(listModa, is.numeric)))
2: tab.disjonctif(X[, act, drop = FALSE])
1: MCA(mydata, graph = FALSE)

0 个答案:

没有答案