In: Computer Science
R Programming: create a vector for 1 to 31 and count the number of even and odds using ifelse()
my_vector<-seq(1,31,1)
print(my_vector)
count_even<-0
count_odd<-0
for(i in my_vector)
{if(i%%2==0)
{count_even<-count_even+1;
}
else
{
count_odd<-count_odd+1;
}
}
cat('no of odd:',count_odd)
cat('\nno of even:',count_even)