为另一部电影创建新列表
你找到了一部杰克·尼科尔森主演的较新电影《无间行者》的影评!
| 评分 | 评论 |
|---|---|
| 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