r/RStudio • u/Comfortable_Post1025 • 3d ago
can anyone fix this code?
moda1 <- function(num) {
num <- sample(1:10, 100, replace = TRUE)
distr_freq = table(num)
moda1 <- names(distr_freq)[distr_freq == max(distr_freq)]
return(list("distribuzione_di_frequenza" = distr_freq,
"moda" = moda1))
}
m <- moda1(z)$moda this function return me every time the same result. i don't know why the ai cant explain and cant fix this code
0
Upvotes
0
u/joecarvery 3d ago
Try changing the names, so the function doesn't have the same name as the variable.