LoslegenKostenlos loslegen

Combine many instruments into one object

One paradigm involves importing data into a new environment. Then you can use eapply() to call a function on each object in the environment, much like what lapply() does for each element of a list. Also like lapply(), eapply() returns a list.

Then you can merge all the elements of the list into one object by using do.call(), which is like having R programmatically type and run a command for you. Instead of typing merge(my_list[[1]], my_list[[2]]], ...), you can type do.call(merge, my_list).

Diese Übung ist Teil des Kurses

Importing and Managing Financial Data in R

Kurs anzeigen

Anleitung zur Übung

  • Use eapply() to call head() on each object in data_env. Assign the result to data_list.
  • Use do.call() and merge() to combine all the elements of data_list into one xts object named data_merged.
  • Since objects in an environment aren't ordered, there's no guarantee what order the columns of data_merged are in. Use OHLC() to order them, and store the data in data_ohlc.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Call head on each object in data_env using eapply
data_list <- ___(data_env, ___)

# Merge all the data_list elements into one xts object
data_merged <- ___(___, data_list)

# Ensure the columns are ordered: open, high, low, close
Code bearbeiten und ausführen