Aproveitando seu código inicial, pensei em algo assim...
### <code r>
AA <- read.table(urls2[1], header=T, as.is=T) AIG <- read.table(urls2[2], header=T, as.is=T) AXP <- read.table(urls2[3], header=T, as.is=T)
Symbols <- c("AA", "AIG", "AXP")
sapply(Symbols, function(x) length(get(x)))
sapply(Symbols, function(x) nrow(get(x)))
sapply(Symbols, function(x) tail(names(get(x)),1))
### Correlações entre leituras diferentes da mesma empresa
cor(AA[2:394], use="pairwise.complete.obs")
cor(AIG[2:394], use="pairwise.complete.obs")
cor(AXP[2:394], use="pairwise.complete.obs")
### Correlações entre mesma leitura das diferentes empresas
### Testando com 4 matrizes
Symbols <- c("AA", "AIG", "AXP", "AXP")
COR <- NULL
for (i in 2:394) {
DAT <- NULL
for (a in Symbols) {
col <- get(a)[,i]
DAT <- cbind(DAT, col)
}
lin <- cbind(ID=i, cor(DAT, use="pairwise.complete.obs"))
colnames(lin) <- c("ID", Symbols)
COR <- rbind(COR, lin)
}
### As 4 matrizes originariam uma matriz cor 4x4 para cada leitura
### As matrizes cor foram empilhadas em uma saída única (COR), onde
### cada 4 linhas são referentes à uma leitura identificada por ID.
head(COR)
# ID AA AIG AXP AXP
# col 2 1.00000000 0.64408120 -0.088884203 -0.088884203
# col 2 0.64408120 1.00000000 -0.109883913 -0.109883913
# col 2 -0.08888420 -0.10988391 1.000000000 1.000000000
# col 2 -0.08888420 -0.10988391 1.000000000 1.000000000
# col 3 1.00000000 0.01779314 0.003447422 0.003447422
# col 3 0.01779314 1.00000000 0.158657131 0.158657131