Advanced R : Vector Flashcards
What is the most important family of data types in base R…..?
Vectors
Vectors comes in ……falvours or type,
Vectors come in two flavours: atomic vectors and lists
There are four primary types of atomic vectors……..
logical, integer, double, and character (which contains strings). Collectively integer and double vectors are known as numeric vectors
Each of the four primary types of vectors has a special syntax to create an individual value, AKA a scalar
string(“a”) , string(‘a’) , double = 0.1234 , integere(1234L), Logicals(TRUE (T)or FALSE(F)),
To create longer vectors from shorter ones, use………short for combine:
dbl_var [1] 1 2 3 4
how to determine type and length of vector?
You can determine the type of a vector with typeof() and its length with length().
R can represent missing, or unknown values, using a special sentinel:……. (short …..). Missing values tend to be infectious: most computations involving a missing value will return another missing value.
NA,,,,for not applicable
………is use to test for the presence of missingness:
is.na()
When you attempt to combine different types they will be coerced in a fixed order:
character → double → integer → logical(CDIL). For example, combining a character and an integer yields a character:
str(c("a", 1)) #> chr [1:2] "a" "1"
how can we coarce delibaterly?
Generally, you can deliberately coerce by using an as.*() function, like as.character(), as.double(), as.integer(), or as.logical(). Failed coercion of strings generates a warning and a missing value:
setting and geeting attribut
You can think of attributes as name-value pairs16 that attach metadata to an object. Individual attributes can be retrieved and modified with attr(), or retrieved en masse with attributes(), and set en masse with structure().
There are only two attributes that are routinely preserved:
names, a character vector giving each element a name.
dim, short for dimensions, an integer vector, used to turn vectors into matrices or arrays.
These are 3 ways of ……. vector
# When creating it:
x
naming a vector