-2

I downloaded some stock data:

require("quantmod")
s <- c("AAPL", "ADBE", "ADI", "ADP", "ADSK") 
e <- new.env()
getSymbols(s, src='yahoo',  from='2015-01-10',  env = e )

#get closing prices
close <- do.call(merge, eapply(e, function(x) Cl(x)))

I found all the pairs of symbol names:

#find all the pairwise permutations
perm<-combn(s,2)
perm
[,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]  [,9]   [,10] 
[1,] "AAPL" "AAPL" "AAPL" "AAPL" "ADBE" "ADBE" "ADBE" "ADI" "ADI"  "ADP" 
[2,] "ADBE" "ADI"  "ADP"  "ADSK" "ADI"  "ADP"  "ADSK" "ADP" "ADSK" "ADSK"

I'd like to take the "close" data for each name and replace for each pair group of "perm" to be able to analyse the pairs later.

Rhodo
  • 1,234
  • 4
  • 19
  • 35
  • why was this q downvoted so that I may better ask the question next time? – Rhodo Jun 15 '15 at 17:34
  • I wasn't a downvoter, but I would say that one possible reason for the downvotes is that you have asked for your data to be reshaped but you have not indicated how you wanted it reshaped -- the last sentence doesn't specify exactly how you want the data stored. Your question could have been improved by showing a small example of how you wanted it stored, perhaps by manually combining one of the pairs. – josliber Jun 16 '15 at 16:30
  • thanks that's helpful – Rhodo Jun 16 '15 at 17:11

1 Answers1

1

If you wanted to get a list of data frames, one for each pair, you could try:

dfs <- lapply(seq_len(ncol(perm)), function(x) close[,paste0(perm[,x], ".Close")])

Now you can get the 2-column data frames for each pair with dfs[[1]], dfs[[2]], etc. You can perform statistical analyses on each pair using the lapply function. Here's a simple example where you get the summary of every paired data frame:

lapply(dfs, summary)
josliber
  • 43,891
  • 12
  • 98
  • 133