Complete the code to calculate the correlation between two numeric vectors x and y.
correlation <- cor(x, y, method = [1])The default and most common method for correlation is "pearson" which measures linear correlation.
Complete the code to calculate the correlation matrix of the dataframe df.
cor_matrix <- cor([1])The function cor() expects a numeric matrix or dataframe. Here, df is the dataframe containing numeric columns.
Fix the error in the code to calculate the Spearman correlation between vectors a and b.
correlation <- cor(a, b, method = [1])The method argument requires the method name as a string, so it must be in quotes.
Fill both blanks to calculate the correlation matrix of numeric columns only from df.
numeric_df <- df[sapply(df, [1])] cor_matrix <- cor(numeric_df, method = [2])
Use is.numeric to select numeric columns, and "pearson" as the correlation method for linear correlation.
Fill all three blanks to calculate the correlation between x and y using Spearman method and round the result to 3 decimals.
result <- round(cor([1], [2], method = [3]), 3)
Use variables x and y as inputs, and specify the method as "spearman" in quotes. Then round the result to 3 decimal places.