聚合列R.

时间:2012-09-15 12:00:33

标签: r split

我是新来的,有问题

    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

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

提前致谢:)

1 个答案:

答案 0 :(得分: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