2

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だけです。

   ## 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))

私が持っていた1つのアイデアは、dfにタイムポイントを含め、2つのデータフレームを一致させてsdesの列を取得することです。次に、それを df w/ only means に cbind します。

しかし、ddplyでこれを行う簡単な方法があるように感じます

4

1 に答える 1

5

要約を使用する必要がない場合:

ddply(x, .(primer), function(DF) DF[DF$mean == max(DF$mean),]) 
于 2012-08-22T14:19:36.710 に答える