开始使用免费开始使用

为另一部电影创建一个新的列表

您找到了另一部较新的 Jack Nicholson 电影《无间行者》(The Departed)的影评!

Scores Comments
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

编辑并运行代码