[R] merge two data frames
arnaud gaboury
arnaud.gaboury at gmail.com
Wed Aug 4 11:52:00 CEST 2010
Dear list,
here are my two data frames:
av <-
structure(list(DESCRIPTION = c("COFFEE C Sep/10", "COPPER Sep/10",
"CORN Dec/10", "CRUDE OIL miNY Sep/10", "GOLD Aug/10", "HENRY HUB
NATURAL GAS Sep/10",
"PALLADIUM Sep/10", "SILVER Sep/10", "SOYBEANS Nov/10", "SPCL HIGH
GRADE ZINC USD",
"SUGAR NO.11 Oct/10", "WHEAT Sep/10"), prix = c(-168.3, -1.60000000000002,
-773.75, -78.75, -1168.3, -0.0919999999999996, -470.75, 1758.5,
-975.25, 1964, -19.09, -605.75), pos = c(-1, 0, -2, -1, -1, 0,
-1, 1, -1, 1, -1, -1), PL = c(-12.03, -31.68, -43.2, -70.49,
-11.88, -95.04, -3.96, -35.64, -30.24, -12.5, -36.09, -4.32)), .Names
= c("DESCRIPTION",
"prix", "pos", "PL"), row.names = c(NA, 12L), class = "data.frame")
zz <-
structure(list(DESCRIPTION = structure(c(1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 13L, 11L, 12L), .Label = c("COFFEE C Sep/10",
"COPPER Sep/10", "CORN Dec/10", "CRUDE OIL miNY Sep/10", "GOLD Aug/10",
"HENRY HUB NATURAL GAS Sep/10", "PALLADIUM Sep/10", "PRM HGH GD ALUMINIUM USD",
"SILVER Sep/10", "SOYBEANS Nov/10", "SPCL HIGH GRADE ZINC USD",
"SUGAR NO.11 Oct/10", "WHEAT Sep/10"), class = "factor"), pl =
c(-8.20000000000002,
2.30000000000001, -47.25, -0.230000000000004, -12.7000000000000,
-0.236, -2, 11.7100000000000, 14.4000000000001, -34.75, -10.75,
55, -0.669999999999998), PL = c(3075.00000000001, -575.000000000003,
2362.5, 115.000000000002, 1270.00000000000, 2360, 200, -292.750000000001,
-720.000000000005, 1737.5, 537.5, -1375, 750.399999999998), POSITION = c(1,
-1, 2, 2, 1, 2, -1, -1, 1, 2, 0, 0, 0), SETTLEMENT = c(167.4,
324.55, 390.75, 76.99, 1160.4, 4.718, 468.75, 2067.71, 1744.1,
978, 0, 0, 0)), .Names = c("DESCRIPTION", "pl", "PL", "POSITION",
"SETTLEMENT"), row.names = c(NA, -13L), class = "data.frame")
I am looking for one data frame with the column $PL=zz$PL+av$PL.
I have been trying using the merge() function and its different
arguments with no sucess.
Any help is appreciated.
Thank You.
More information about the R-help
mailing list