Question

Logical vectors in R can contain NA in addition to TRUE and FALSE. An NA in...

Logical vectors in R can contain NA in addition to TRUE and FALSE. An NA in a logical context can be interpreted as “unknown.” Consider the following commands:

4 > 3 & NA

## [1] NA

4 < 3 & NA

## [1] FALSE

4 < 3 | NA

## [1] NA

4 > 3 | NA

## [1] TRUE

Explain why there is a difference in the output of these four commands. Why are they not all NA?

Homework Answers

Answer #1

& operator needs to evaluate all the conditions starting from left and return TRUE only when all the conditions are TRUE. It will return FALSE as soon as the first FALSE conditions is encountered. It may also return NA if NA is encountered.

Hence first command returns NA and second command returns FALSE.

| (or) operator will need to evaluate all the conditions and return TRUE if any of the conditions is TRUE (best case). Thats why fourth one returns TRUE.

Third one (4 < 3 | NA) returns NA because the best case is NA. 4<3 is FALSE but | operator needs to evaluate if the next condition is true or not FALSE and it finds that it is NA which is returned.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
3. (a) (2 marks) Consider R 3 over R. Show that the vectors (1, 2, 3)...
3. (a) Consider R 3 over R. Show that the vectors (1, 2, 3) and (3, 2, 1) are linearly independent. Explain why they do not form a basis for R 3 . (b) Consider R 2 over R. Show that the vectors (1, 2), (1, 3) and (1, 4) span R 2 . Explain why they do not form a basis for R 2 .
Cartesian Vectors (Write True or False) 1. Geometric vectors have both magnitude and direction but Cartesian...
Cartesian Vectors (Write True or False) 1. Geometric vectors have both magnitude and direction but Cartesian vectors have only magnitude. 2. Unit vectors have a magnitude of one but no direction 3. The product of a vector and scalar is a vector. 4. There is no such thing as a zero vector. 5. A Cartesian vector uses coordinates to describe it fully 6. .The dot product of two vectors is a vector.
1.Consider vectors A→A→, B→B→, and their resultant R→R→. How can you express its direction as a...
1.Consider vectors A→A→, B→B→, and their resultant R→R→. How can you express its direction as a counterclockwise angle from positive x in terms of A?Ax, A?Ay, B?Bx, and B?By? 2.How can you express impulse in terms of mass and initial and final velocities? 3.The time difference between a 2km/s2km/s S-wave and a 6km/s6km/s P-wave recorded at a certain point is 10seconds10seconds. How far is the epicenter of the earthquake from that point?
Here are some vectors in R 4 : u1 = [1 3 −1 1] u2 =...
Here are some vectors in R 4 : u1 = [1 3 −1 1] u2 = [1 4 −1 1] u3 = [1 0 −1 1] u4 = [2 −1 −2 2] u5 = [1 4 0 1] (a) Explain why these vectors cannot possibly be independent. (b) Form a matrix A whose columns are the ui’s and compute the rref(A). (c) Solve the homogeneous system Ax = 0 in parametric form and then in vector form. (Be sure the...
True or False A.The dot product of two vectors is always less than the product of...
True or False A.The dot product of two vectors is always less than the product of the lengths of the vectors. B. All linear combinations of the vectors u= (u1,u2) and v= (v1,v2) form the parallelogram whose adjacent sides are u and v. C. If A and B are square matrices of the same size, then the second column of AB can be obtained by multiplying the second column of A to the matrix B. D. The vector that starts...
7. Answer the following questions true or false and provide an explanation. • If you think...
7. Answer the following questions true or false and provide an explanation. • If you think the statement is true, refer to a definition or theorem. • If false, give a counter-example to show that the statement is not true for all cases. (a) Let A be a 3 × 4 matrix. If A has a pivot on every row then the equation Ax = b has a unique solution for all b in R^3 . (b) If the augmented...
Assume that the following variables are set as follow P is True, Q is False, R...
Assume that the following variables are set as follow P is True, Q is False, R is False. Solve for X X = (P ∧ ~Q) ∨ (~P ∧ ~R) Solve for Y Y=(P  Q ) ∨ (R  ~P)                                                                                                                                                                            20 points Give one example and the mathematical symbol for the following: A universal set A subset A proper subset An empty set The intersect of two sets. 25 points Convert the following the numbers (must show all...
Determine if each of the following statements is true or false. If it’s true, explain why....
Determine if each of the following statements is true or false. If it’s true, explain why. If it’s false explain why not, or simply give an example demonstrating why it’s false (a) If λ=0 is not an eigenvalue of A, then the columns of A fo ma basis of R^n. (b) If u, v ∈ R^3 are orthogonal, then the set {u, u − 3v} is orthogonal. (c) If S1 is an orthogonal set and S2 is an orthogonal set...
True or false? All proteins must fold in the four structural levels to be functional in...
True or false? All proteins must fold in the four structural levels to be functional in simple terms can you explain why?
True or False. Explain why it is true or false. 1) A change in people’s preferences...
True or False. Explain why it is true or false. 1) A change in people’s preferences always leads to an increase in the Terms of Trade for a country. 2) With free trade, the industrialized countries gain at the expense of the agricultural countries. 3) In a 2X2X2 model, free trade leads to identical rental rate levels in both countries. 4) In the Neo-Classical model in autarky, a country can produce only one good at a time.