R语言truthTable函数报错: 'Error: non-numeric argument to binary operator'
R语言中使用truthTable函数时,如果遇到'Error: non-numeric argument to binary operator'错误,通常意味着在使用二元运算符时,其中一个操作数不是数字类型。
在你的代码中:
ZZB <- truthTable(performance1,
conditions = 'A1,B1,C1,D1,E1',
outcome = 'Y2',
incl.cut = 0.8,
pri.cut = 0.7,
# n.cut = 1,
sort.by = 'incl,n,out,pri',
show.cases = FALSE)
错误可能出现在以下参数中的一个或多个上:'incl.cut'、'pri.cut'、'n.cut'。
解决方法:
- 检查参数类型: 首先,检查'incl.cut'、'pri.cut'、'n.cut'的值是否为数字类型。如果不是,使用
as.numeric()函数将它们转换为数字类型。例如:
ZZB <- truthTable(performance1,
conditions = 'A1,B1,C1,D1,E1',
outcome = 'Y2',
incl.cut = as.numeric(0.8),
pri.cut = as.numeric(0.7),
# n.cut = 1,
sort.by = 'incl,n,out,pri',
show.cases = FALSE)
-
检查数据类型: 如果参数已经是数字类型,那么问题可能出现在其他地方。检查
performance1、conditions和outcome的值是否正确,并确保它们符合你的预期。特别是conditions和outcome的值,它们应该是字符串类型,但如果它们包含非字符串的字符,也会导致错误。 -
检查函数参数: 仔细阅读
truthTable函数的文档,确认每个参数的预期数据类型,并确保你提供的参数符合要求。
通过以上步骤,你应该能够解决'Error: non-numeric argument to binary operator'错误,并成功运行truthTable函数。
原文地址: https://www.cveoy.top/t/topic/bAV6 著作权归作者所有。请勿转载和采集!