将R中的名称分类并存储在另一列中

时间:2018-11-07 04:36:19

标签: r

当我想将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

0 个答案:

没有答案