R中的k个模式下的下标类型“列表”无效

时间:2019-11-07 06:58:43

标签: r k-means

我有一个包含8848个观测值的数据集,其中包含46个变量。在将kmodes应用于所需列时,会产生错误。

我尝试如下

library(klaR)
Data_Value <- read.csv("Path", header=TRUE)
var1<-subset(Data_Value,Data_Value$Improvement=="Improved")
var2<-subset(Data_Value,Data_Value$Improvement=="Not Improved")
data<-rbind(var1,var2[1:4424,])
clustering<-(data[c(2,3,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46)])
kmodes(na.omit(clustering),5, iter.max = 10,weighted = TRUE)

我遇到以下错误:

Error in `[.default`(weights[[j]], sapply(as.character(modes[, j]), function(z) return(which(names(weights[[j]]) ==  : 
  invalid subscript type 'list'

当我在数据中使用33列时,出现上述错误。请建议我哪里出了问题?

dput(head(clustering,5)):

structure(list(column2 = structure(c(1L, 1L, 3L, 1L, 1L), .Label = c("Adult", 
"Child", "Infant"), class = "factor"), column3 = structure(c(3L, 
5L, 5L, 5L, 5L), .Label = c("ALK", "DALK", "EK", "Others", "PK", 
"THPK"), class = "factor"), column30 = structure(c(1L, 
1L, 1L, 1L, 1L), .Label = c("Improved", "Not Improved"), class = "factor"), 
  column32 = c(FALSE, FALSE, FALSE, FALSE, TRUE), column33 = c(FALSE, 
    FALSE, FALSE, FALSE, TRUE), column34= c(FALSE, FALSE, 
    FALSE, FALSE, FALSE), column35 = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE), column36 = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE), column37 = c(FALSE, 
    FALSE, FALSE, FALSE, FALSE),column38 = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE),column39 = c(FALSE, 
    FALSE, FALSE, FALSE, FALSE), column40 = c(FALSE, 
    FALSE, FALSE, FALSE, FALSE), column41 = c(FALSE, 
    FALSE, FALSE, FALSE, FALSE), column42 = c(FALSE, 
    FALSE, FALSE, FALSE, FALSE),column43 = c(FALSE, FALSE, 
    FALSE, FALSE, FALSE), column44 = c(FALSE, FALSE, FALSE, 
    FALSE, FALSE),column45 = c(FALSE, FALSE, FALSE, 
    FALSE, FALSE), column46= c(FALSE, FALSE, FALSE, FALSE, 
    FALSE)), row.names = c(4L, 5L, 7L, 13L, 14L), class = "data.frame")

0 个答案:

没有答案