An expression is any construct that an interpreter can evaluate. The there are mainly three types of expressions, corresponding to the basic data types:
In most languages, the basic data types (numbers, characters, and booleans) are scalars, meaning that they come in units: One can define ONE number, ONE string, or ONE boolean value.
The basic data types are the basic chunk or data that an interpreter can swallow. More complex aggregated data are usually built from these basic data types using the language basic data structures (called also containers, or collections) to aggregate the basic data types. This is not the case in R.
At contrast with most languages, R comes with vectorized basic data types, which are already collections of what, in another language as Python for example, one would call basic data types.
In R, there is nothing such as a single string, a single boolean, or a single number. Evething comes arrange from start in a vector of strings, vector of boolean, or vector of numbers, which, in R lingo, are called:
As in most other linguages, the basic data types have the usual operations defined on them:
However, since, in R, the basic types are vectorized, these operations are defined element wise.
In [1]:
%load_ext rmagic
In [2]:
%%R
x = c(1, 2, 3)
y = c(2, 3, 5)
Caution: In R, all the operations on basic types are vectorized, which means that they are performed element-wise.
In [5]:
%%R
z = x + y
z = x * y
z = x ^ y
#etc.
print(z)
In [22]:
%%R
x = rep('Student', 10)
y = sample(1:100, 10)
print(x)
print(y)
In [24]:
%%R
z = paste(x,y, sep=':')
print(z)
In [11]:
%%R
x = rep(T, 10)
y = sample(c(T,F), 10, replace=T)
print(x)
print(y)
In [18]:
%%R
print(x | y)
print(x & y)
print(!y)
In [14]:
%%R
print(any(y))
print(all(y))
In [ ]: