简体   繁体   English

xj [i]中的错误:当R中的LDA执行时,无效的下标类型'list'

[英]Error in xj[i] : invalid subscript type 'list' when do LDA in R

mydat=structure(list(spent = c(73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 
73.5, 73.5, 73.5, 73.5, 73.5, 29.74, 29.74, 29.74, 29.74, 29.74, 
29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 73.71, 73.71, 73.71, 
73.71, 73.71, 73.71, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 
73.5, 73.5, 73.5, 73.5, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 
29.74, 29.74, 29.74, 29.74, 29.74, 73.71, 73.71, 73.71, 73.71, 
73.71, 73.71), realpurchase_cash = c(501, 502, 503, 504, 505, 
506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 
519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 73.5, 73.5, 
73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 73.5, 29.74, 
29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 29.74, 
29.74, 73.71, 73.71, 73.71, 73.71, 73.71, 73.71), id = c(123L, 
123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 
123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 
123L, 123L, 123L, 123L, 123L, 124L, 124L, 124L, 124L, 124L, 124L, 
124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 
124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L
), flag = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("spent", 
"realpurchase_cash", "id", "flag"), class = "data.frame", row.names = c(NA, 
-56L))

i want perform Linear discriminant analysis. 我想进行线性判别分析。 (lda function comes from MASS library) (lda函数来自MASS库)

here my code 我的代码

index <- sample(1:nrow(mydat),round(0.70*nrow(mydat)))
train <- mydat[index,]
test <- mydat[-index,]
library("MASS")
fit=lda(flag~spent+realpurchase_cash, mydat, subset = train)
library("caret") 
str(mydat)
library(InformationValue)
predicted <- predict(fit,test,type='response')
optCutOff <- optimalCutoff(test$flag, predicted)[1] 
confusionMatrix(test$flag, predicted, threshold = optCutOff)

but after this string 但是这个字符串之后

fit=lda(flag~spent+realpurchase_cash, mydat, subset = train)

i get the error 我收到了错误

Error in xj[i] : invalid subscript type 'list'

How to fix this error. 如何解决此错误。 What's wrong? 怎么了?

subset wants a vector and you give him a data frame (ie a list). subset想要一个向量,你给他一个数据框(即一个列表)。 Do

lda(flag ~ spent + realpurchase_cash, mydat, subset=index)

or, since train is already your desired subset, just 或者,因为train已经是您想要的子集,只是

lda(flag ~ spent + realpurchase_cash, data=train)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 xj[i] 中的错误:无效的下标类型“列表” - Error in xj[i] : invalid subscript type 'list' 运行 lm() 错误:xj[i] 中的错误:无效的下标类型“列表” - Running lm() errror: Error in xj[i] : invalid subscript type 'list' xj[i] 中的错误:无效的下标类型“闭包” - Error in xj[i] : invalid subscript type 'closure' 尝试构建树给出:`[.default`(xj, i) 中的错误:无效的下标类型“列表” - Trying to build tree gives: Error in `[.default`(xj, i) : invalid subscript type 'list' R Steamgraph错误:“无效的下标类型列表” - R Steamgraph error: “invalid subscript type list” 错误:R中的下标类型'list'无效 - Error: invalid subscript type 'list' in R 在R中使用并行plyr和data.table时出错:do.ply(i)中的错误:任务1失败 - “无效的下标类型&#39;列表&#39;” - Error using using parallel plyr and data.table in R: Error in do.ply(i) : task 1 failed - “invalid subscript type 'list'” R:无效的下标类型&#39;list&#39; - R: invalid subscript type 'list' 如何根据另一个列表对列表进行子集化? .subset(x, j) 中的错误:无效的下标类型“列表” - How do I subset a list based on another list? Error in .subset(x, j) : invalid subscript type 'list' R中未使用的参数和无效的下标类型列表错误 - unused arguments and invalid subscript type list error in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM