当我想将Apple,Mango,Pear等名称分类为Fruits时,您将如何进行分类。在此示例中,我想将级别归类为暴力,但是代码给我一个错误“评估错误:'x'必须为数字。”
levels <- c(-Inf, 'assault' , 'robbery' , 'battery' , 'weapons
violation', 'sex offense', 'offense involving children','crim sexual
assault','kidnapping','homicide','human trafficking','intimidation',
'concealed carry license violation', Inf)
labels <- c("Violence")
df %>% mutate(crime_categories = cut(df.Primary.Type, levels, labels =
labels))
df$crime_categories