我正在处理数据,我特别希望使用间隔对其进行分类。
List<string> columnOne = new List<string>();
foreach(DatagridViewColumn Column in DatagridView2.Column)
{
if (Column[0].Value.toString().Contains("lastName")
{
foreach(DatagridViewRow row in DatagridView2.Rows)
{
columnOne.add(row.Value.toString());
}
}
}
命令非常有用,我可以使用,例如,
cut
以两个间隔对数据进行分类。处理是更复杂问题的一部分,最终需要将新数据分配给自动生成的区间。
最有效的方法是什么?因为尝试阅读data <- seq(1, 10)
cut(data, 2)
>> [1] (0.991,5.5] (0.991,5.5] (0.991,5.5] (0.991,5.5] (0.991,5.5] (5.5,10] (5.5,10] (5.5,10] (5.5,10] (5.5,10]
Levels: (0.991,5.5] (5.5,10]
进行分类似乎太脏了......
答案 0 :(得分:1)
这是使用基础R的快速方法:
# Find intervals use original data
labs = levels(cut(data, 2))
labs_df = cbind(lower = as.numeric( sub("\\((.+),.*", "\\1", labs) ),
upper = as.numeric( sub("[^,]*,([^]]*)\\]", "\\1", labs) ))
# Find intervals on new data
data_new = sample(1:10)
interval_idx = findInterval(data_new, labs_df[,1])
interval_idx
interval = labs[interval_idx]
data.frame(data_new, interval_idx, interval)