如果nrow = 1,则跳过ddply

时间:2014-01-30 19:34:42

标签: r plyr skip

我有一个ddply遍历IP列表并在每个IP上应用乐趣。我希望只有在nrow(ip.data) > 1时才能返回值。否则,我希望ddply跳过该IP并继续。我怎么能这样做?

例如:

pd.outs <- ddply(server_ips, .(ip), function(x) get.ip.outs(x$ip, data))

nrow(ip.data)将提供(数据)子集中行数的长度。

1 个答案:

答案 0 :(得分:6)

一种方法是返回NULL nrow(x)==1

pd.outs <- ddply(server_ips, .(ip), function(x) {
  if (nrow(x) == 1) {
    return(NULL)
  }
  get.ip.outs(x$ip, data)
})