I'm trying to run an MCA on a data set using FactoMineR, and keep getting this error despite that fact that my data is Y/N (ie. not numerical binary 1/0):
Error in which(unlist(lapply(listModa, is.numeric))) : argument to 'which' is not logical
I've read that R categorical data is related to factor type, so even if you have characters you could get this error. But I don't know what 'factor type' means, or how I can change that. I have been trying to use this code:
require(FactoMineR)
head(mydata)
cats = apply(mydata, 2, function(x) nlevels(as.factor(x)))
mca1 = MCA(mydata, graph = FALSE)
I'm a complete R novice and don't understand a lot of the coding language but really want to learn! Any help would be much appreciated as this is for a Masters project
> 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)