Question: 3. Use a for loop to iterate over the elements of a vector x, and increment a counter nodd when the element of x is

 3. Use a "for" loop to iterate over the elements of

3. Use a "for" loop to iterate over the elements of a vector x, and increment a counter nodd when the element of x is odd. Then print the number of even and odd elements of x. Recall that an integer y is odd if y%%2==1, and otherwise y is even. Use the R commands below to generate a vector "x" of length 100. ''{r} set.seed(10) X=sample(1:10,100, replace=T) Then modify the following code. '{r} nodd=0 #initialize the counter nodd, which counts the number of odd elements of x # for () {increment nodd in the loop when the associated element of x is odd} #neven= calculate neven using the length of x and nodd. paste("number of odd elements ", nodd) #paste("number of even elements = ", neven) For this vector x, the number of odd elements should be 56. (*5 points*)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!