1

我是新来的,有问题

    Year       Market         Winner          BID
1  1990        ABC             Apple          0.1260
2  1990        ABC             Apple          0.1395
3  1990        EFG             Pear           0.1350
4  1991        EFG             Apple          0.1113
5  1991        EFG             Orange         0.1094

对于每年和两个市场(即ABC、EFG),分别检查Apple 和Pear 关于投标价格变量BID 的组合数据是否存在潜在异常值。5 确定您观察到存在潜在异常值的实例。

我设法仅按年份分离数据

y <- c(1, seq(300))
year1991 <- subset(X, y < 39)
year1991
Year1991 <- year1991[, c(1,2,3,5)]
Year1991

现在我需要有关正确的 R 命令的帮助,以仅选择(查看)市场列的 ABC,其他列值仍然存在。

是否可以一次进行多次分离?或一步一步

可以给我一个提示,如果我想以这种方式查看日期,我该如何排除

   Year       Market         Winner          BID
1  1990        ABC             Apple         0.1260
2  1990        ABC             Apple         0.1395

  Year       Market         Winner          BID
1 1990        EFG             Pear           0.1350

就像试图拆分“市场”但仍然看到整个价值列表

提前致谢 :)

4

1 回答 1

0
> df
  Year Market Winner    BID
1 1990    ABC  Apple 0.1260
2 1990    ABC  Apple 0.1395
3 1990    EFG   Pear 0.1350
4 1991    EFG  Apple 0.1113
5 1991    EFG Orange 0.1094


library(plyr)
# Then you can break up the data into chunks of year x market.
# I split your data.frame into a list. You can do further things with that list.
# alternatively, you can use ddply and add a function to do your hw bit and collate all
# results back into a final data.frame. This should be a helpful start.
> dlply(df, .(Year,Market))
$`1990.ABC`
  Year Market Winner    BID
1 1990    ABC  Apple 0.1260
2 1990    ABC  Apple 0.1395

$`1990.EFG`
  Year Market Winner   BID
3 1990    EFG   Pear 0.135

$`1991.EFG`
  Year Market Winner    BID
4 1991    EFG  Apple 0.1113
5 1991    EFG Orange 0.1094
于 2012-09-15T17:47:07.977 回答