Complete the code to convert the data from long to wide format using pivot_wider.
library(tidyr) data <- data.frame(name = c('A', 'A', 'B', 'B'), key = c('x', 'y', 'x', 'y'), value = c(1, 2, 3, 4)) wide_data <- pivot_wider(data, names_from = [1], values_from = value)
The names_from argument specifies the column whose values will become new column names. Here, key is correct.
Complete the code to specify the values column in pivot_wider.
wide_data <- pivot_wider(data, names_from = key, values_from = [1])The values_from argument specifies the column with values to fill the new columns. Here, it's value.
Fix the error in the code to correctly pivot the data wider.
wide_data <- pivot_wider(data, names_from = key, values_from = [1])The column name is value, not values or val. Use the exact column name.
Fill both blanks to create a wide data frame with names as rows and keys as columns.
wide_data <- pivot_wider(data, names_from = [1], values_from = [2])
Use key for names_from and value for values_from to pivot correctly.
Fill all three blanks to pivot the data wider and rename the new columns with uppercase keys.
wide_data <- pivot_wider(data, names_from = [1], values_from = [2], names_prefix = [3])
Use key for names_from, value for values_from, and add prefix "COL_" to new column names.