Complete the code to add a new column 'total' as the sum of 'x' and 'y'.
library(dplyr) data <- tibble(x = 1:3, y = 4:6) data <- data %>% mutate(total = x [1] y)
The mutate() function adds a new column. Using + sums the columns x and y.
Complete the code to create a new column 'ratio' as 'x' divided by 'y'.
library(dplyr) data <- tibble(x = 10:12, y = 2:4) data <- data %>% mutate(ratio = x [1] y)
The / operator divides x by y to create the 'ratio' column.
Fix the error in the code to correctly add a new column 'diff' as the difference between 'a' and 'b'.
library(dplyr) data <- tibble(a = 5:7, b = 3:5) data <- data %>% mutate(diff = a [1] b)
The difference is calculated by subtracting b from a using the - operator.
Fill both blanks to create a new column 'score' as the product of 'm' and 'n' plus 10.
library(dplyr) data <- tibble(m = 2:4, n = 5:7) data <- data %>% mutate(score = m [1] n [2] 10)
First multiply m and n with *, then add 10 with +.
Fill all three blanks to create a new column 'result' as the uppercase of 'name', length of 'name', and check if length is greater than 4.
library(dplyr) data <- tibble(name = c('Anna', 'Brian', 'Clara')) data <- data %>% mutate(result = list([1], [2], [3]))
tolower() instead of toupper().Use toupper(name) for uppercase, nchar(name) for length, and nchar(name) > 4 to check if length is greater than 4.