Vector
  • There are six types of atomic vectors, logical, integer, double, complex, character and raw
  • Index starts from 1
  • Create Vector
    a = 1:10 # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
    b = seq(1, 10, by = 2) # 1, 3, 5, 7, 9
    c = c('apple','red',5,TRUE)
    		
    Accesing
    a = 1:4 # 1, 2, 3, 4
    
    print(a[1]) # access element, index starts from 1
    
    print(a[c(1, 4)]) # 1, 4
    
    print(a[-2]) # 1, 3, 4, not including 2
    
    print(a[a>2]) # 3, 4
    
    print(a[a%%2 == 0]) # 2, 4, even numbers
    		
    Operations
    5 %in% a # check if 5 is in vector a
    
    a = 1:4
    b = seq(2, 8, by = 2)
    
    print(a+b)
    print(a-b)
    print(a*b)
    print(a/b)
    
    print(a/2)
    
    a = 1:10
    b = sort(a, decreasing = TRUE) # sort
    
    print(b)