-1

我有一个如下所示的数据框。我想删除重复出现的键元组 ( Parameter, Value) 并选择具有最小值的那个mse

> df
              mse     Parameter Value
    1    25.86760 Training_size   100
    2     8.42944 Training_size   200
    3    58.80860 Training_size   300
    4    34.37760 Training_size   400
    5    99.61530 Training_size   500
    6    19.77290 Training_size   600
    7    24.76670 Training_size   700
    8   587.96900 Training_size   800
    9   538.02500 Training_size   900
    10   60.39630 Training_size  1000
    11  137.07600 Training_size  2000
    12   62.05740 Training_size  3000
    13    8.44762 Training_size   200
    14    8.44610 Training_size   200
    15    8.44871 Training_size   200
    16    8.42939 Training_size   200
    17   11.78550 Training_size   200
    18   11.78520 Training_size   200
    19 1726.44000 Training_size   200
    20 1726.44000 Training_size   200
    21 1726.43000 Training_size   200
    22    8.42939 Training_size   200
    23    8.42942 Training_size   200
    24    8.42939 Training_size   200
    25    8.42938 Training_size   200

我想改为:

              mse     Parameter Value
    1    25.86760 Training_size   100
    3    58.80860 Training_size   300
    4    34.37760 Training_size   400
    5    99.61530 Training_size   500
    6    19.77290 Training_size   600
    7    24.76670 Training_size   700
    8   587.96900 Training_size   800
    9   538.02500 Training_size   900
    10   60.39630 Training_size  1000
    11  137.07600 Training_size  2000
    12   62.05740 Training_size  3000
    25    8.42938 Training_size   200

我怎样才能做到这一点?

4

3 回答 3

3

如果您想用于大数据,那么您可以考虑使用data.table

library(data.table)
DT <- as.data.table(mydata)
setkey(DT,Parameter,Value)  # optional, for further speed
DT[,min(mse),by="Parameter,Value"]
        Parameter Value        V1
 1: Training_size   100  25.86760
 2: Training_size   200   8.42938
 3: Training_size   300  58.80860
 4: Training_size   400  34.37760
 5: Training_size   500  99.61530
 6: Training_size   600  19.77290
 7: Training_size   700  24.76670
 8: Training_size   800 587.96900
 9: Training_size   900 538.02500
10: Training_size  1000  60.39630
11: Training_size  2000 137.07600
12: Training_size  3000  62.05740
于 2013-09-02T13:54:33.083 回答
2

在基础中使用aggregate函数

> aggregate(.~Value+Parameter, data=df, FUN=min)
   Value     Parameter       mse
1    100 Training_size  25.86760
2    200 Training_size   8.42938
3    300 Training_size  58.80860
4    400 Training_size  34.37760
5    500 Training_size  99.61530
6    600 Training_size  19.77290
7    700 Training_size  24.76670
8    800 Training_size 587.96900
9    900 Training_size 538.02500
10  1000 Training_size  60.39630
11  2000 Training_size 137.07600
12  3000 Training_size  62.05740
于 2013-09-02T13:36:40.590 回答
0

Parameter我认为“删除键元组( , )的重复出现的value过程包含在“选择最小的那个”的过程中mse。真的(如果我理解正确的话)您只想构建一个数据框,其中包含 和mse的每个唯一组合Parameter的最小值value。(请注意,元组不是 R 中定义的数据类型。

plyr软件包非常适合此。

require(plyr)
ddply(df, c("Parameter", "value"), summarise, min(mse))
于 2013-09-02T13:36:29.253 回答