Questions
COMM_V 205 101 102 103 2025W1 Assignment B2 (R)
Multiple choice
Assume that you have created the variable bacon correctly (from the previous question). You want to create a column, called bacon_number, which is equal to 1 for each actor who has ever appeared in a movie with Kevin Bacon in Actors data frame. You want bacon_number to be equal to 0 for Kevin Bacon, and you want it to be equal to NA for any other observations. That means that this question does not ask to generate all possible Bacon numbers. It only focuses on Bacon number 0 (for Kevin Bacon) and Bacon number 1 (for those who have ever appeared in a movie with Kevin Bacon). For all others actors, Bacon number should be NA. For example, Tom Cruise appeared with Kevin Bacon in the 1992 movie A Few Good Men, making Tom Cruise’s Bacon Number equal to 1. We want bacon_number to be equal to 1 for all observations for Tom Cruise, even in movies where he did not appear together with Kevin Bacon. For example, we would want to make sure that Tom Cruise’s bacon_number is still equal to 1 when he appears in Rain Man in 1988 or Edge of Tomorrow in 2014. Recall the assumption that you have created the variable bacon successfully before. The following sequence of commands comes right after the previous question. That is, in your Actors data frame you have the 7th column called bacon and it is equal to 1 for every observations of Kevin Bacon and 0 otherwise. Also, recall that Kevin Bacon’s actor_ID is 10000001. Which of the following series of commands will achieve the above task? There is AT LEAST ONE correct option, but you MUST SELECT ALL correct option(s). There is no partial credit. Note that if you put a negative sign (i.e., -) in front of a column name you specified in select(), it means that you want to select all the columns except the one indicated with a negative sign. For example, Actors %>% select(-best_actor) is identical to Actors %>% select( actor_ID, actor_l, actor_f, title, year, best_actress).
Options
A.bacon_temp <- Actors %>% group_by(title, year) %>% summarize(bacon_number_temp = max(bacon))
data_temp <- left_join(Actors, bacon_temp)
data_temp2 <- data_temp %>% group_by(actor_ID) %>% summarize(bacon_number = max(bacon_number_temp))
Actors <- left_join(data_temp, data_temp2)
Actors$bacon_number[Actors$bacon_number == 0] <- NA
Actors$bacon_number[Actors$actor_ID == 10000001] <- 0
Actors <- Actors %>% select(-bacon_number_temp)
B.bacon_temp <- Actors %>% group_by(title, year) %>% mutate(bacon_number_temp = max(bacon))
data_temp <- left_join(Actors, bacon_temp)
data_temp2 <- data_temp %>% group_by(actor_ID) %>% mutate(bacon_number = max(bacon_number_temp))
Actors <- left_join(data_temp, data_temp2)
Actors$bacon_number[Actors$bacon_number == 0] <- NA
Actors$bacon_number[Actors$actor_ID == 10000001] <- 0
Actors <- Actors %>% select(-bacon_number_temp)
C.Actors <- Actors %>% group_by(title, year) %>% summarize(bacon_number_temp = max(bacon))
Actors <- Actors %>% group_by(actor_ID) %>% summarize(bacon_number = max(bacon_number_temp))
Actors$bacon_number[Actors$bacon_number == 0] <- NA
Actors$bacon_number[Actors$actor_ID == 10000001] <- 0
Actors <- Actors %>% select(-bacon_number_temp)
D.Actors <- Actors %>% group_by(title, year) %>% mutate(bacon_number_temp = max(bacon))
Actors <- Actors %>% group_by(actor_ID) %>% mutate(bacon_number = max(bacon_number_temp))
Actors$bacon_number[Actors$bacon_number == 0] <- NA
Actors$bacon_number[Actors$actor_ID == 10000001] <- 0
Actors <- Actors %>% select(-bacon_number_temp)
E.All of the options are incorrect.
View Explanation
Verified Answer
Please login to view
Step-by-Step Analysis
To tackle this question, we need to determine which sequences of dplyr commands correctly construct bacon_number such that:
- bacon_number is 0 for Kevin Bacon (actor_ID 10000001),
- bacon_number is 1 for actors who have appeared in a movie with Kevin Bacon, and
- bacon_number is NA for all other actors.
The approach in each option uses a two-step strategy: (a) compute a per-movie indicator of whether Kevin Bacon is in that movie by taking the max of bacon within each (title, year) group, and (b) propagate that signal to each actor by taking the max across that actor’s rows, then recode 0 to NA and set Kevin Bacon’s Bacon number to 0. Below I analyze each option in turn.
Option 1:
Actors <- Actors %>% group_by(title, year) %>% mutate(bacon_number_temp = max(bacon))
Actors <- Actors %>% group_by(actor_ID) %>% mutate(bacon_number = max(bacon_number_temp))
Actors$bacon_number[Actors$bacon_number......Login to view full explanationLog in for full answers
We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!
Similar Questions
This function in the library of Pandas allows you to manipulate data and create new variables (please choose all the correct answers, one or more):
Question at position 17 ________ is a set of commands used to update and query a database.DDL DML DPL DCL
Please create the following data frame: library(tidyverse)student <- tibble( sid = c(66666,66666,66666,66666,66666,66666,22222,22222,22222,22222,22222, 11111,11111,11111,11111,11111,44444,44444,44444,44444,44444, 44444, 55555,55555,55555,55555,55555,55555, 33333,33333,33333,33333,33333,33333, 77777), course = c("COMM101", "COMM102", "COMM103", "COMM201", "COMM204","COMM205", "COMM101", "COMM102", "COMM103", "COMM201","COMM204", "COMM101", "COMM102", "COMM103", "COMM201", "COMM205", "COMM101", "COMM102", "COMM103", "COMM201","COMM204", "COMM205", "COMM101", "COMM102", "COMM103","COMM201", "COMM204", "COMM205", "COMM101", "COMM102", "COMM103", "COMM201", "COMM204","COMM205", "COMM205"), year = c(2016, 2016, 2016, 2017, 2017, 2017, 2016, 2016, 2017, 2017,2017,2016, 2016, 2016, 2017, 2017, 2016, 2016, 2016, 2016, 2017, 2017,2016, 2016, 2016, 2016, 2017, 2017,2016, 2016, 2016, 2017, 2017, 2017, 2017), grade = c(85, 88, 72, 67, 80, 90, 77, 77, 77, 77, 77, 78, 82, 82, 80, 90, 80, 80, 80, 85, 85, 85, 79, 80, 81, 82, 83, 84, 90, 88, 95, 80, 80, 80, 99)) You wanted to find out how many unique students have taken courses in 2016. student %>% filter(year == 2016) %>% XXXX(sid) %>% summarise(XXXX(sid)) The result of your code should look something like this: # A tibble: 1 × 1 XXXXXXXXXX <int> 1 6 Please complete the code below. student %>% filter(year == 2016) %>% [Fill in the blank] (sid) %>% summarise([Fill in the blank] (sid))
Question at position 51 A database is maintained and queried using the data mapping language (DML).TrueFalse
More Practical Tools for Students Powered by AI Study Helper
Making Your Study Simpler
Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!