问题描述
所以我正在尝试使用 cut 函数将数字变量转换为分类变量,并且我不断收到意外字符错误,但是已经三重检查了我的拼写,所以不确定是什么问题,有人可以帮忙吗?这是代码:
[ca_timechcare_categorical:= cut(ca_timechcare,break=c(0,36,72,108,Inf),
include.lowest=TRUE,labels=c("Very_Low","Low","High","Very_High"))]
dataset[,table(ca_timechcare_categorical)]
这是我收到的错误:
Error: unexpected ')' in "labels=c("Very_Low","Very_High"))"
谢谢!
更新:现在已按照以下建议将代码更正为:
dataset <- as.data.table(US_COVID19_study)
dataset[,ca_timechcare_categorical:= cut(survey_design_childcare,breaks = c(36,labels= c("Very_Low",table(ca_timechcare_categorical)]
但现在我收到此错误:
Error in `:=`(ca_timechcare_categorical,cut(survey_design_childcare,:
Check that is.data.table(DT) == TRUE. Otherwise,:= and `:=`(...) are defined for use in j,once only and in particular ways. See help(":=").
有什么想法吗??再次感谢!
解决方法
我假定您使用data.table并且因此vestigal操作数:=
两件事情:你缺少的括号中的逗号和breaks
{不{1}}
break