0
0
R Programmingprogramming~10 mins

Correlation analysis in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the correlation between two numeric vectors x and y.

R Programming
correlation <- cor(x, y, method = [1])
Drag options to blanks, or click blank then click option'
A"pearson"
B"spearman"
C"kendall"
D"linear"
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid method name like "linear" causes an error.
Confusing method names with other correlation types.
2fill in blank
medium

Complete the code to calculate the correlation matrix of the dataframe df.

R Programming
cor_matrix <- cor([1])
Drag options to blanks, or click blank then click option'
Adf
Bdata
Cmatrix
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list instead of a dataframe causes an error.
Passing an undefined variable name.
3fill in blank
hard

Fix the error in the code to calculate the Spearman correlation between vectors a and b.

R Programming
correlation <- cor(a, b, method = [1])
Drag options to blanks, or click blank then click option'
ASpearman
Bspearman
C"spearman"
DSPEARMAN
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the method name causes an error.
Using incorrect capitalization without quotes.
4fill in blank
hard

Fill both blanks to calculate the correlation matrix of numeric columns only from df.

R Programming
numeric_df <- df[sapply(df, [1])]
cor_matrix <- cor(numeric_df, method = [2])
Drag options to blanks, or click blank then click option'
Ais.numeric
Bis.character
C"pearson"
D"kendall"
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting non-numeric columns causes errors in cor().
Using method names without quotes.
5fill in blank
hard

Fill all three blanks to calculate the correlation between x and y using Spearman method and round the result to 3 decimals.

R Programming
result <- round(cor([1], [2], method = [3]), 3)
Drag options to blanks, or click blank then click option'
Ax
By
C"spearman"
D"pearson"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names.
Not quoting the method name causes errors.