0
0
R Programmingprogramming~15 mins

Correlation analysis in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Correlation analysis
📖 Scenario: You are a data analyst working with a small dataset of students' study hours and their exam scores. You want to find out if there is a relationship between how much students study and how well they perform on the exam.
🎯 Goal: Build a simple R program that calculates the correlation between study hours and exam scores using the Pearson method.
📋 What You'll Learn
Create a data frame with exact columns and values
Create a variable for the correlation method
Calculate the correlation using the cor() function with the method variable
Print the correlation result
💡 Why This Matters
🌍 Real World
Correlation analysis helps understand relationships between variables, like study time and exam scores, which is useful in education, business, and science.
💼 Career
Data analysts and scientists use correlation to find patterns and insights in data that guide decisions and predictions.
Progress0 / 4 steps
1
Create the data frame
Create a data frame called students with two columns: study_hours and exam_scores. Use these exact values: study_hours = c(2, 3, 5, 6, 8) and exam_scores = c(50, 60, 75, 80, 90).
R Programming
Need a hint?

Use the data.frame() function to create the data frame with the exact column names and values.

2
Set the correlation method
Create a variable called method and set it to the string "pearson" to specify the correlation method.
R Programming
Need a hint?

Assign the string "pearson" to the variable method.

3
Calculate the correlation
Calculate the correlation between study_hours and exam_scores from the students data frame using the cor() function with the method variable. Store the result in a variable called correlation.
R Programming
Need a hint?

Use cor() with the two columns and the method variable.

4
Print the correlation result
Print the value of the correlation variable using the print() function.
R Programming
Need a hint?

Use print(correlation) to show the correlation value.