r_cheat_sheet_1


R cheat sheet

Basics

Concatenation, length of vectors, numeric operations, matrix creation

Concatenation


In [2]:
x = c(1,2,3,4,5,6) #concatenate to create a vector
x


  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6

In [4]:
length(x)


6

Numeric operations

vector 1 + vector 2 is a element by element summation


In [5]:
y = c(8,9,10,11,12,14)
x_y = x+y
x_y


  1. 9
  2. 11
  3. 13
  4. 15
  5. 17
  6. 20

List all variables in memory

use ls()


In [6]:
ls()


  1. 'x'
  2. 'x_y'
  3. 'y'

remove variables using rm(var_name)


In [8]:
rm('x_y')
ls()


  1. 'x'
  2. 'y'

Getting help

use ?symbol to get help


In [7]:
?ls

Build a matrix

use matrix(data, nrow, ncol) method to build a nd matrix


In [9]:
m1 = matrix(data= x, nrow=2, ncol=3)
m1


135
246

In [ ]: