Write an R program to perform linear regression and predict values based on a numeric data frame.
MediumProblem 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))
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