在ddply中使用Summary来基于一列的max()获取整行 [英] using summarize in ddply to get entire row based on max() of one column
本文介绍了在ddply中使用Summary来基于一列的max()获取整行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
df1
primer timepoints mean sde
Acan 0 1.0000000 0.000000e+00
Acan 20 0.8758265 7.856192e-02
Acan 40 1.0575400 4.680159e-02
Acan 60 1.2399106 2.238616e-01
Acan 120 1.1710685 2.085558e-02
Acan 240 1.6430670 NA
Acan 360 1.7747940 NA
我想要的是平均值(对于任何这些时间点)的最大值,它是对应的sde.
all I want is the max value of mean (for any of these timepoints) w/ it's corresponding sde.
## this will only get me the mean obviously
x <- ddply(x, .(primer), summarize, max = max(mean))
primer max
Acan 1.774794
## if I were to do this I would obviously not have just the maximum values
x <- ddply(x. .(primer,sde), summarize, max = max(mean))
我曾经想过的一个想法可能是在df中包含时间点,然后匹配两个数据帧以获得一列sdes.然后将其绑定到df w/仅意味着.
one idea I had would be to may be to include timepoints in the df then match the two data frames to get a column of sdes. Then cbind that to the df w/ only means.
但是我觉得有一种更简单的方法可以做到这一点
But I feel as if there is an easier way to do this w/ ddply
推荐答案
如果您不必使用摘要:
ddply(x, .(primer), function(DF) DF[DF$mean == max(DF$mean),])
这篇关于在ddply中使用Summary来基于一列的max()获取整行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文