#
# CHAPTER 14: Coercion
#
# creation of objects with a prescribed mode; is and as functions
# some coercion is automatic; othertimes done by programmer
# basic data types: numeric, integer, complex, character, logical
#
is.numeric(5) # is 5 numeric?
is.integer(5) # is 5 an integer?
as.integer(5) # coerce 5 to be an integer
is.integer(c(2L:7L)) # is this a vector of integers?
is.character(5) # is 5 character?
as.character(5) # coerce 5 to be character
is.complex(5 + 12i) # is 5 + 12i complex?
is.atomic(2:7) # is this vector atomic?
sqrt(-1) # square root of -1
sqrt(as.complex(-1)) # square root of -1 + 0i
x = logical(5) # establish x as a vector of 5 logical elements
x # display x
is.logical(x) # are the elements of x logicals?
as.numeric(x) # coerce x to be numeric
x # display x
y = c(1, 2, NA, 4, 5) # a missing value (Not Available)
y # display y
is.na(y) # are there NAs in y?
z = y[!is.na(y)] # assign z to y with missing values removed
z # display z