開始使用免費開始

為另一部電影建立新的清單

你找到另一部較新 Jack Nicholson 電影的影評:The Departed!

分數 評語
4.6 I would watch it again
5 Amazing!
4.8 I liked it
5 One of the best movies
4.2 Fascinating plot

把與這部電影相關的所有資訊(例如片名、演員、影評)收在同一個變數裡會很方便。由於這些資料的型狀不同,把它們放進清單變數是很自然的做法。

movie_title(電影片名)與 movie_actors(部分演員姓名)已經在你的工作空間中。

本練習屬於課程

R 入門

檢視課程

練習說明

  • 建立兩個向量 scorescomments,包含表格中影評的資訊。
  • 計算 scores 向量的平均值,存成 avg_review
  • scorescomments 合併成名為 reviews_df 的資料框。
  • 建立名為 departed_list 的清單,內含 movie_titlemovie_actors、作為影評資料框的 reviews_df,以及平均分數 avg_review,並將它列印出來。

動手互動練習

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

# Use the table from the exercise to define the comments and scores vectors
scores <- c(4.6, 5, 4.8, 5, ___
comments <- c("I would watch it again", "Amazing!", "I liked it", "One of the best movies", ___ 

# Save the average of the scores vector as avg_review


# Combine scores and comments into the reviews_df data frame


# Create and print out a list, called departed_list

編輯並執行程式碼