Complete the code to load the tidyr package.
library([1])The tidyr package contains the pivot_longer() function used to reshape data from wide to long format.
Complete the code to reshape the data frame df from wide to long format using pivot_longer().
df_long <- pivot_longer(df, cols = [1], names_to = "variable", values_to = "value")
The cols argument expects column names as strings inside a vector, so c("col1", "col2") is correct.
Fix the error in the code to correctly specify the columns to pivot.
df_long <- pivot_longer(df, cols = [1], names_to = "variable", values_to = "value")
The columns must be specified as a character vector with double quotes, so c("col1", "col2") is correct. Single quotes also work in R but the question expects double quotes for consistency.
Fill both blanks to create a long format data frame with columns named "key" and "val".
df_long <- pivot_longer(df, cols = [1], names_to = [2], values_to = "val")
The cols argument should be the columns to pivot, here c("col1", "col2"). The names_to argument sets the new column name for the original column names, here "key".
Fill all three blanks to pivot columns "X1" and "X2" into a long format with names in "variable" and values in "value".
df_long <- pivot_longer(df, cols = [1], names_to = [2], values_to = [3])
The columns to pivot are c("X1", "X2"). The new column for names is "variable" and for values is "value".