gpt4 book ai didi

r - 如何将逻辑变量转换为 Rattle 中的因子

转载 作者:行者123 更新时间:2023-12-04 12:04:06 25 4
gpt4 key购买 nike

我正在使用 Rattle 运行 randomForest针对我的训练数据集。其中一个变量具有值 FALSETRUE .

     > str(mydata)
'data.frame': 421570 obs. of 2 variables:
$ Trial : int 1 1 1 1 1 1 1 1 1 1 ...
$ IsHoliday : logi FALSE FALSE FALSE FALSE FALSE FALSE ...

我能够将其转换为 R 中的一个因子。
     > mydata$IsHoliday <- factor(mydata$IsHoliday)
> str(mydata)
'data.frame': 421570 obs. of 2 variables:
$ Trial : int 1 1 1 1 1 1 1 1 1 1 ...
$ IsHoliday : Factor w/ 2 levels "FALSE","TRUE": 1 1 1 1 1 1 1 1 1 1 ...

当我写 data.frame到 CSV 并使用 Rattle 加载它,我再次将其视为合乎逻辑的。因此,我收到错误消息 Error in na.roughfix.data.frame(x) + na.roughfix only works for numeric or factor
任何帮助表示赞赏。提前致谢

最佳答案

我认为你应该尝试包括“as”

mydata$IsHoliday=as.factor(mydata$IsHoliday)   

关于r - 如何将逻辑变量转换为 Rattle 中的因子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23106559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com