R中的Bucketing数据给出错误
我正试图将我的数据分为不同的类别,并在这样做的同时面临一个问题。我不知道哪里出了问题。请帮忙R中的Bucketing数据给出错误,r,R,我正试图将我的数据分为不同的类别,并在这样做的同时面临一个问题。我不知道哪里出了问题。请帮忙 new_df<-original_df new_df$bucket_column<-cut( as.numeric( new_df$value_for_bucket_column), breaks=c(0,1,2,3,4,5,6,7,14,21,28,60,90,180,365,Inf),
new_df<-original_df
new_df$bucket_column<-cut(
as.numeric(
new_df$value_for_bucket_column),
breaks=c(0,1,2,3,4,5,6,7,14,21,28,60,90,180,365,Inf),
labels = c("1 Day","1-2 Days","2-3 Days","3- Days",
"4-5 Days","5-6 Days", "1 Week",
"1-2 Weeks","2-3 Weeks","3-4 Weeks",
"1-2 Months","2-3 Months","3-6 Months",
"6-12 Months","More than a Year"))
new\u df您需要提供更多信息,但是您的cut(…)
可能返回零长度向量。as.numeric(新的\u-df$value\u用于\u-bucket\u列)
确实是有效的24783长度数字向量吗?如果我删除as.numeric函数,而只为\u-bucket\u列提供新的\u-df$value\u,那么它将成功完成。但是,当我尝试使用table(new_df$bucket_column)将输出列转换为列,然后尝试查看值时,它会显示区段0>的table。您能否显示str(new_df$value_for_bucket_column)
的输出或重现问题的示例数据?请提供一个可重复的示例。
Error in `$<-.data.frame`(`*tmp*`, "bucket_column", value = integer(0)) :
replacement has 0 rows, data has 24783