I'm using linear regression to attempt and forecast certain data. Even though there is no fault, it is strange. In order to forecast data2, which only has 1000 rows, I used a linear regression that I generated from data1, which has 4000 rows.

So, in my opinion, the variable's output should only contain 1000 rows. However, the 4000 variables never stop appearing. I have no idea what's wrong.

model = lm(train\$latitude train\$crashes)
Model, newdata = test, prediction1 = predict
data.frame = csv1
(Predicted = prediction1, Id = c(1:1000))
I infer from this code that it simply needs to forecast "test" data, which consists of 1000 rows. The statement reads, "Arguments suggest varied number of rows: 1000, 4337," though The train data in this instance has 4337 rows, hence the 4337.
Jun 23 31 views

## 1 answer to this question.

Alter this sentence:

model = lm(train\$latitude train\$crashes) to

lm(crashes latitude, data=train) is the model.
The dataset name should ideally only be supplied once in data= when utilising the formula interface, as opposed to being specified for each variable as train\$crashes, etc.

The same crashes latitude formula will be used on the new dataset that you have supplied when you execute predict with newdata=.

You should have been alarmed by the following warning I received when attempting to reproduce your problem:

data.frame with the following formulas: train = crashes = rnorm(1000), latitude = sample(1:1000), test = crashes = rnorm(4377), sample(1:4377)

lm(train\$crashes train\$latitude) is the model.
prediction1: predict (model, newdata = test)
The phrase "newdata" had 4337 rows, while the variables were only discovered to have 1000 rows.
answered Jun 24 by
• 2,960 points

## why the predict() function does have different rows in R

I'm using linear regression to attempt and ...READ MORE

## What does the sink function do in R?

sink diverts R output to a connection ...READ MORE

## R function for finding the index of an element in a vector?

The function match works on vectors : x <- sample(1:10) x # ...READ MORE

+1 vote

## Which function can I use to clear the console in R and RStudio ?

Description                   Windows & Linux           Mac Clear console                      Ctrl+L ...READ MORE

## Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

## Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

## Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE