別の映画のリストを新たに作成する
ジャック・ニコルソン出演の別の映画『ディパーテッド』のレビューが見つかりました。
| スコア | コメント |
|---|---|
| 4.6 | I would watch it again |
| 5 | Amazing! |
| 4.8 | I liked it |
| 5 | One of the best movies |
| 4.2 | Fascinating plot |
タイトル、出演俳優、レビューなど映画に関するさまざまな情報を1つの変数にまとめておくと便利です。これらのデータは形式が異なるため、リスト変数にまとめるのが自然な方法です。
映画のタイトルを格納した movie_title と、一部の出演俳優名を格納した movie_actors は、すでにワークスペースに用意されています。
この演習はコースの一部です
R 入門
演習の手順
- 表に示されているレビューの情報をもとに、
scoresとcommentsという2つのベクトルを作成してください。 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