'I´m getting an error 'train' and 'class' have different lengths'

library(class)
library(caret)

b_data <- b[,-1]
b_data <- mutate(b_data,
dia = fct_recode(b$ventas))
b$ventas <- as.factor(b$ventas)
b$estado <- as.factor(b$estado)
round(prop.table(table(b_data$dia)) * 100, 1)
normalize <- function(x){
return ((x - min(x))/(max(x) - min(x)))
}
b_data_n <- as.data.frame(lapply(b_data[1:5], normalize))

nrow(b)
[1] 887622

b_training <- b_data_n[1:443811,]
b_test <- b_data_n[443812:887622,]
b_training_labels <- b_data[1:443811,1]
b_test_labels <- b_data[443812:887622,1]
b_test_predicted <- knn(b_training, b_test, cl = b_training_labels, k = 943) 

"Error in knn(b_training, b_test, cl = b_training_labels, k = 943) : 'train' and 'class' have different lengths"

dim(b_test)
[1] 443811      5

dim(b_training)
[1] 443811      5

length(b_training_labels)
[1] 1

My data looks like this:

 talk_sec wait_sec pause_sec length_in_sec called_count hora estado ventas
 <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <fct> <fct>
 1 777 9 0 0 0 11 JAL 
1 2 677 1 0 0 0 9 JAL 
1 3 0 4 11 0 0 10 JAL 
1 4 0 29 4 0 0 12 JAL 1
r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source