เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Cognostics from nested data frames

Let's compute the average close price, average volume, and annual return as cognostics. The variables that these are based on, open, close, and volume, are inside the nested data frame data in our by_symbol dataset.

Note that a function, annual_return(), has been provided for convenience.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Visualizing Big Data with Trelliscope in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Use map() to compute over every nested data frame of data.
  • Inside the map function, create a summary data frame containing the average close price, the average volume, and the annual percentage return. Take a look at by_symbol$data[[1]] to recall the column names that are available.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

library(trelliscopejs)
library(dplyr)
library(purrr)

annual_return <- function(x)
  100 * (tail(x$close, 1) - head(x$open, 1)) / head(x$open, 1)

# Compute by_symbol_avg
by_symbol_avg <- mutate(by_symbol,
  stats = ___(___, function(x) {
    data_frame(
      mean_close = mean(x$___),
      mean_volume = mean(x$___),
      annual_return = annual_return(x)
    )
  }))
แก้ไขและรันโค้ด