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

Programming Exercises

Write an R program to perform linear regression and predict values based on a numeric data frame.

Medium

Problem Statement

Write an R program to perform linear regression and predict values based on a numeric data frame.

Sample Input

Data Frame: 
 x y
1 1 2
2 2 4
3 3 6
4 4 8

Sample Output

Predicted Value for x=5: 10

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure data <- # Create the data frame model <- # Fit a linear regression model prediction <- predict(model, data.frame(x = 5)) print(paste("Predicted Value for x=5:", prediction))
Log in or sign up to run or submit your code.Log inSign up
Input
Data Frame: 
 x y
1 1 2
2 2 4
3 3 6
4 4 8
Expected Output
Predicted Value for x=5: 10