av bv tv u l value s
30 120 360 330 210 6600 0.005238424
35 125 360 325 200 6875 0.005028887
40 130 360 320 190 7150 0.004835468
45 135 360 315 180 7425 0.004656377
50 140 360 310 170 7700 0.004490078
55 145 360 305 160 7975 0.004335247
60 150 360 300 150 8250 0.004190739
65 155 360 295 140 8525 0.004055554
70 160 360 290 130 8800 0.003928818
75 165 360 285 120 9075 0.003809763
80 170 360 280 110 9350 0.003697711
dput(DF)
df<-structure(list(av = c(30, 35, 40, 45, 50, 55, 60, 65, 70, 75,
80), bv = c(120, 125, 130, 135, 140, 145, 150, 155, 160, 165,
170), tv = c(360, 360, 360, 360, 360, 360, 360, 360, 360, 360,
360), u = c(330, 325, 320, 315, 310, 305, 300, 295, 290, 285,
280), l = c(210, 200, 190, 180, 170, 160, 150, 140, 130, 120,
110), value = c(6600, 6875, 7150, 7425, 7700, 7975, 8250, 8525,
8800, 9075, 9350), s = c(0.005238424, 0.00502888704, 0.00483546830769231,
0.00465637688888889, 0.00449007771428572, 0.00433524744827586,
0.0041907392, 0.00405555406451613, 0.003928818, 0.00380976290909091,
0.00369771105882353)), .Names = c("av", "bv", "tv", "u", "l",
"value", "s"), row.names = c(1L, 13L, 25L, 37L, 49L, 61L, 73L,
85L, 97L, 109L, 121L), class = "data.frame")
DF2
av bv tv u l value
30 120 0 0 0 0
30 120 20 0 0 0
30 120 40 10 0 550
30 120 60 30 0 1650
30 120 120 90 0 4950
30 120 180 150 30 6600
dput(DF2)
df2<-structure(list(av = c(30, 30, 30, 30, 30, 30), bv = c(120, 120,
120, 120, 120, 120), tv = c(0, 20, 40, 60, 120, 180), u = c(0,
0, 10, 30, 90, 150), l = c(0, 0, 0, 0, 0, 30), value = c(0, 0,
550, 1650, 4950, 6600)), .Names = c("av", "bv", "tv", "u", "l",
"value"), row.names = c(1L, 2602L, 5203L, 7804L, 10405L, 13006L
), class = "data.frame")
我想要做的就是將的值加入df
至df2
,其中df$bv == df2$bv
。 df2
將在df
中有更多相同的bv
值,因此會有一些重複的s
值。
我嘗試以下
newDF <- ddply(df2, .(bv,tv), summarise, s = df[df$bv %in% df2$bv,]$s)
雖然這不是爲我工作,也許是因爲我真的不明白這個函數的可變參數。
真的所有其他列在這一點上是任意的,但我想保持整個數據幀不變。
我認爲第一行可以被編輯: – Doug
dfsub < - DF [,C( 'BV', 'S')] – Doug
如果那更快你燁。我認爲這會更容易看到我在做什麼。這有幫助嗎? –