I have a simple function which finds numbers divisible by 4 in the following vector: x4 <- (2 4 6 8 10 12 14)
. But the function returns the values, and I want it to return indexes.
myef2 <- function(x){
li2 <- NULL
for(i in x){
if(i %% 4 == 0) li2 <- c(li2, i)
}
return(li2)
}
the result is [1] 4 8 12. How do I modify it to give me a vector of indexes instead? Thanks for any help!