R predict.lm function gives output of wrong size.
stocks = read.csv("some-file.csv", header = TRUE)
## 75% of the sample size
smp_size <- floor(0.75 * nrow(stocks))
## set the seed to make your partition reproductible
set.seed(123)
train_ind <- sample(seq_len(nrow(stocks)), size = smp_size)
train <- stocks[train_ind, ]
test <- stocks[-train_ind, ]
model = lm ( train$Open ~ train$Close, data=train)
model
predicted<-predict.lm(model, test$Open)
length(test$Open)
length(predicted)
length(test$Close)
> length(test$Open)
[1] 16994
> length(predicted)
[1] 50867
> length(test$Close)
[1] 16994
Why this is happening? output length of the predict functions should be equal to length of the test$Open , right?