148k views
2 votes
Y <- c(TRUE, 2) will coerce the elements to all be ___.

A) y <- c(TRUE, 2) will coerce the elements to all be logical.
B) y <- c(TRUE, 2) will coerce the elements to all be integer.
C) y <- c(TRUE, 2) will coerce the elements to all be character.
D) y <- c(TRUE, 2) will coerce the elements to all be numeric.

User Tuzzer
by
9.3k points

1 Answer

2 votes

Final answer:

In R, when a logical and numeric data types are combined in a vector, the logical is coerced to its numeric form. The expression y <- c(TRUE, 2) results in y being a numeric vector with the values 1 and 2.

Step-by-step explanation:

When combining different data types in a vector in R, coercion happens so that all the elements are of the same type. For the expression y <- c(TRUE, 2), R will coerce the logical value TRUE to its numeric equivalent, which means that the resulting vector y will contain numeric values (1 for TRUE and 2). Therefore, the correct answer is D) y <- c(TRUE, 2) will coerce the elements to all be numeric.

User KING SABRI
by
8.6k points