R - Basic Data Types and Vectors
A. Basic Data Types
Numeric
Decimal values are called numerics.
Integers
TRUE has value 1, FALSE has value 0
Complex
Are defined using the pure imaginary value i
Logical
Logical operators
- & and
- | or
- ! negation
B. Vectors
A vector is a sequence of data elements of the same basic type. Members are called components.
To find number of components:
1. Combining Vectors
Vectors are combined using the function c
2. Vector Arithmetics
If two vectors are of unequal length, the shorter one will be recycled in order to match the longer vector.
3. Vector Index
We retrive values in a vector by declaring an index inside a single squera bracket []
. The result is other vector
If the index is negative, it would strip the member whose position has the same absoluite value as the negative index.
4. Numeric Index Vector
a new vector canb be sliced from a given vector with a numeric indes vector, which contains intended member positions of the original vector to be retrieved.
An index vector allows duplicate values
To produce a vector slice between two members, we can use the colon operator “:”
###5. Logical Index Vector
A new vector can be sliced from a given vector with a logical index vector, which has the same length as the original vector. Its members are TRUE if the corresponding members in the original vector are to be included in the slice, and FALSE if otherwise.