The below code is written on RStudio, and this code will remove every element in the vector which is a multiple of x for each x in the vector.
When I run the function, the loop only works for the first element in the vector, ie, 2, and it doesn't verify the remaining elements such as 3,4,5,6. How can I correct it?
my_function <- function(n){
X <- 2:n
i <- 2
for (x in X){
while (x*i <= n){
a <- match(x*i,X)
X <- X[-(a)]
i <- i+1
}
print(X)
}
}