What will be the output of the following R code? [code] x<- c (“a”,” b”) as.numeric(x)[/code]

Tam ca

New member
What will be the output of the following R code?
Code:
       x<- c (“a”,” b”)
       as.numeric(x)
A. [1] 1 2
B. [1] TRUE TRUE
C. [1] NA NA (Warning message: NAs introduced by coercion)
D. [1] NAN
 
Answer: c
Explanation: Characters cannot be expressed as numeric. Therefore NA’s are printed as output. NA will specify the missing elements in the list. When nonsensical coercion takes place, you will usually get a warning from R.
 

Tìm kiếm

Back
Top