開始使用免費開始

讓 getSymbols() 回傳所擷取的資料

在上一個練習中,getSymbols() 會自動建立一個與你提供的代號同名的物件。這個練習要帶你讓 getSymbols() 直接回傳資料,這樣你就能自行指派輸出了。

有兩個引數可以讓 getSymbols() 回傳資料:

  1. 設定 auto.assign = FALSE
  2. 設定 env = NULL

這兩種方法在功能上等效,但 auto.assign = FALSE 更能清楚描述行為。建議使用它,因為你之後更容易記得 auto.assign = FALSE 的意義。

本練習屬於課程

在 R 匯入與管理金融資料

檢視課程

練習說明

  • 下載 SPY 資料,並用 auto.assign 引數將它指派給名為 spy 的物件。
  • 使用 str() 函式檢視 spy 物件的結構。
  • 下載 JNJ 資料,並用 env 引數將它指派給名為 jnj 的物件。
  • 再次使用 str(),但這次套用在 jnj 物件上。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Assign SPY data to 'spy' using auto.assign argument


# Look at the structure of the 'spy' object


# Assign JNJ data to 'jnj' using env argument


# Look at the structure of the 'jnj' object
編輯並執行程式碼