1
Good evening everyone, I want to write a function in R that checks the even elements and display them on screen later. From that I wrote the following code:
pares <- function(v){
for(i in v){
if ((v[i]%%2)==0){
b[i]<-c(v[i])
}
}
print(b)
}
pares(a)
with this I received the following reply from the compiler: [1] 0 2 NA 4 NA 6 NA 8 NA 10 I don’t know what’s causing it, could someone help me remove these "NA"? Thank you very much in advance.