R - datatypes, variables¶
In [2]:
Copied!
x = c(1,2,3,4,5,6) #concatenate to create a vector
x
x = c(1,2,3,4,5,6) #concatenate to create a vector
x
- 1
- 2
- 3
- 4
- 5
- 6
In [4]:
Copied!
length(x)
length(x)
6
Numeric operations¶
vector 1 + vector 2 is a element by element summation
In [5]:
Copied!
y = c(8,9,10,11,12,14)
x_y = x+y
x_y
y = c(8,9,10,11,12,14)
x_y = x+y
x_y
- 9
- 11
- 13
- 15
- 17
- 20
List all variables in memory¶
use ls()
In [6]:
Copied!
ls()
ls()
- 'x'
- 'x_y'
- 'y'
remove variables using rm(var_name)
In [8]:
Copied!
rm('x_y')
ls()
rm('x_y')
ls()
- 'x'
- 'y'
Getting help¶
use ?symbol
to get help
In [7]:
Copied!
?ls
?ls
Build a matrix¶
use matrix(data, nrow, ncol)
method to build a nd matrix
In [9]:
Copied!
m1 = matrix(data= x, nrow=2, ncol=3)
m1
m1 = matrix(data= x, nrow=2, ncol=3)
m1
1 | 3 | 5 |
2 | 4 | 6 |
In [ ]:
Copied!