Skip to main content
added another method
Source Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160

Defining, for convenience,

o = FinancialData["SP500", "Open", {2015}]
c = FinancialData["SP500", "Close", {2015}]

the two can be combined into 3 columns, - date, open, close" with

MapIndexed[Join[#, c[[#2, 2]]] &, o]
(* {{{2015, 1, 2}, 2058.9, 2058.2}, {{2015, 1, 5}, 2054.44, 2020.58}, {{2015, 1, 6}, 2022.15, 2002.61}, ...} *)

Other methods include

Cases[MapThread[Join, {o, c}], {l1_, l2_, l3_, l4_} -> {l1, l2, l4}, Infinity] 

Table[{o[[i, 1]], o[[i, 2]], c[[i, 2]]}, {i, Length[o]}]

Defining, for convenience,

o = FinancialData["SP500", "Open", {2015}]
c = FinancialData["SP500", "Close", {2015}]

the two can be combined into 3 columns, - date, open, close" with

MapIndexed[Join[#, c[[#2, 2]]] &, o]
(* {{{2015, 1, 2}, 2058.9, 2058.2}, {{2015, 1, 5}, 2054.44, 2020.58}, {{2015, 1, 6}, 2022.15, 2002.61}, ...} *)

Other methods include

Cases[MapThread[Join, {o, c}], {l1_, l2_, l3_, l4_} -> {l1, l2, l4}, Infinity]

Defining, for convenience,

o = FinancialData["SP500", "Open", {2015}]
c = FinancialData["SP500", "Close", {2015}]

the two can be combined into 3 columns, - date, open, close" with

MapIndexed[Join[#, c[[#2, 2]]] &, o]
(* {{{2015, 1, 2}, 2058.9, 2058.2}, {{2015, 1, 5}, 2054.44, 2020.58}, {{2015, 1, 6}, 2022.15, 2002.61}, ...} *)

Other methods include

Cases[MapThread[Join, {o, c}], {l1_, l2_, l3_, l4_} -> {l1, l2, l4}, Infinity] 

Table[{o[[i, 1]], o[[i, 2]], c[[i, 2]]}, {i, Length[o]}]
Source Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160

Defining, for convenience,

o = FinancialData["SP500", "Open", {2015}]
c = FinancialData["SP500", "Close", {2015}]

the two can be combined into 3 columns, - date, open, close" with

MapIndexed[Join[#, c[[#2, 2]]] &, o]
(* {{{2015, 1, 2}, 2058.9, 2058.2}, {{2015, 1, 5}, 2054.44, 2020.58}, {{2015, 1, 6}, 2022.15, 2002.61}, ...} *)

Other methods include

Cases[MapThread[Join, {o, c}], {l1_, l2_, l3_, l4_} -> {l1, l2, l4}, Infinity]