I have 2 data.frames, the first is a data.frame that contains stock data and a column with a unique identifier (column "ISIN") , as shown below:
>Teste=data.frame(matrix(runif(20), nrow=5, ncol=4))
Teste$ISIN <- c("A1","A2","A3","A4","A5")
colnames(Teste) <- c("AVG_VOLUME","AVG_RETURN","VOL","PRICE","ISIN")
AVG_VOLUME AVG_RETURN VOL PRICE ISIN
Stock 1 0.7028197 0.09264265 0.002169411 100 A1
Stock 2 0.7154557 0.03314615 0.004839466 100 A2
Stock 3 0.4038030 0.04347487 0.003441471 100 A3
Stock 4 0.5392530 0.06414982 0.004482528 100 A4
Stock 5 0.8720084 0.09615865 0.008081017 100 A5
My second data.frame has an "ISIN" column but they are not unique, as shown below:
Teste2 <- data.frame(matrix(runif(10), nrow=5, ncol=2))
Teste2$ISIN <- c("A1","A1","A3","A2","A2")
X1 X2 ISIN
1 0.0273074 0.6829592 A1
2 0.1928437 0.3768154 A1
3 0.9693224 0.3331828 A3
4 0.9434274 0.1549707 A2
5 0.6211476 0.3360101 A2
What I would like to do is fetch in the data.frame Test the value of the column "AVG_VOLUME" corresponding to the "ISIN" of data.frame Test2 and add this information as a new column in Test2, resulting in:
X1 X2 ISIN AVG_VOLUME
1 0.0273074 0.6829592 A1 0.7028197
2 0.1928437 0.3768154 A1 0.7028197
3 0.9693224 0.3331828 A3 0.4038030
4 0.9434274 0.1549707 A2 0.7154557
5 0.6211476 0.3360101 A2 0.7154557
What is the best way to get this result, type a PROCV in excel?