Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write an R program to find the correlation between two numeric vectors.

Easy

Problem Statement

Write an R program to find the correlation between two numeric vectors.

Sample Input

Vector 1: c(1, 2, 3, 4, 5)
Vector 2: c(2, 4, 6, 8, 10)

Sample Output

Correlation: 1

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure vector1 <- c(1, 2, 3, 4, 5) vector2 <- c(2, 4, 6, 8, 10) correlation <- cor(vector1, vector2) print(paste("Correlation:", correlation))
Log in or sign up to run or submit your code.Log inSign up
Input
Vector 1: c(1, 2, 3, 4, 5)
Vector 2: c(2, 4, 6, 8, 10)
Expected Output
Correlation: 1