Please enable JavaScript.
Coggle requires JavaScript to display documents.
R (Everything is a vector here) - Coggle Diagram
R
Everything is a
vector
here
A basic vector is
atomic
, meaning it contains exactly one type of data
If a vector contains multiple data types, they are all transformed to a single data type, which is known as
implicit coercion
The hierarchy is as follows:
NULL <
raw <
logical <
integer <
doube <
complex <
character <
list <
expression
Using
as.datatype()
we can make the coercion
explicit
, setting the data type for all the elements.
data types
numeric
all non-complex numbers
integer
only integers; requires less memory, but must be assigned explicitly
to assign, add 'L' at the end of the number (e.g. '3L')
double
most numbers, including integers by default
NaN
assigned to mathematical operations with undefined results (like dividing by zero)
technically belongs to the 'double' data type
complex
complex numbers (the ones that include i)
character
strings and text
logical
boolean values (TRUE and FALSE)
NULL
nothing at all, a void
raw
raw hexadecimal data
list
a container for various elements that can belong to different data types
expression
a container for R scripts
A special case:
NA
each data type has its own NA, but the default type for it is logical
Some basic operations
sum()
returns the sum of the elements
mean()
returns the mean of the elements
We can access the elements of a vector using
indexing
like so:
n[x]
Indices start
from 1
, not 0
If we do some operations between two vectors of a different length, if the longer vector is a multiple of the shorter one, the latter will be
recycled
: repeated as many times as necessary