為另一部電影建立新的清單
你找到另一部較新 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 入門
練習說明
- 建立兩個向量
scores與comments,包含表格中影評的資訊。 - 計算
scores向量的平均值,存成avg_review。 - 將
scores與comments合併成名為reviews_df的資料框。 - 建立名為
departed_list的清單,內含movie_title、movie_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