Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Do the followign excercise in the R language and answers the following questions

ID: 3587059 • Letter: D

Question

Do the followign excercise in the R language and answers the following questions.

Exercise 4.2 a. Store the vector c(7,1,7,10,5,9,10,3,10,8) as foo. Identify the elements greater than 5 OR equal to 2. Store the vector c(8,8,4,4,5,1,5,6,6,8) as bar. Identify the ele- ments less than or equal to 6 AND not equal to 4. Identify the elements that satisfy (a) in foo AND satisfy (b) in bar. Store a third vector called baz that is equal to the element-wise sum of foo and bar. Determine the following: i. The elements of baz greater than or equal to l b. c. d. equal to 15 The elements of the vector obtained via an element-wise division of baz by foo that are greater than 4 OR less than or equal to 2 ii. Confirm that using the long version in all of the preceding exercises performs only the first comparison (that is, the results each match the first entries of the previously obtained vectors). e.

Explanation / Answer

The code is given below and the comments are for your understanding.

#a.

foo <- c(7,1,7,10,5,9,10,3,10,8)

vector = c()

for(val in foo)

{

if(val>5 && val==2)

{

vector[i] <- val;

}

}

vector

#b.

bar <- c(8,8,4,4,5,1,5,6,6,8)

vector = c()

for(val in bar)

{

if(val<=6 && val!=4)

{

vector[i] <- val;

}

}

vector

#c.

c(foo,bar)

#d.

baz <- rowSums( cbind (foo,bar), na.rm=TRUE) # You can use either this or simply

# baz <- (foo + bar)

#i.

vector = c()

for(val in baz)

{

if(val>=146 && val!=15)

{

vector[i] <- val;

}

}

vector

#ii.

arr <- (baz/foo)

vector = c()

for(val in arr)

{

if(val>4 && val<=2)

{

vector[i] <- val;

}

}

vector

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote