Learn R Programming

expss (version 0.5.1)

vectors: Infix operations on vectors - append, diff, intersection, union, replication

Description

  • %a% a(ppends) second argument to first argument.
  • %u% u(ites) first and second arguments. Remove elements from second argument that exist in first argument.
  • %d% d(iffs) second argument from first argument. Second argument could be a function which returns logical value. In this case elements of first argument which give TRUE will be removed
  • %i% i(ntersects) first argument and second argument. Second argument could be a function which returns logical value. In this case elements of first argument which give FALSE will be removed
  • %e% e(xclusive OR). Returns elements that contained only in one of arguments.
  • %r% r(epeats) first argument second argument times
All these functions preserve names of vectors and doesn't remove duplicates. For %d% and %i% one can use criteria functions. See criteria for details.

Usage

e1 %a% e2
e1 %u% e2
e1 %d% e2
e1 %i% e2
e1 %e% e2
e1 %r% e2

Arguments

e1
vector
e2
vector (or function for %d%, %i%)

Value

vector

Examples

Run this code

1:4 %a% 5:6   # 1:6

1:4 %a% 4:5   # 1,2,3,4,4,5

1:4 %u% 4:5   # 1,2,3,4,5

1:6 %d% 5:6   # 1:4

# function as criterion
1:6 %d% gt(4) # 1:4

1:4 %i% 4:5   # 4

# function as criterion
letters %i% perl("[a-d]") # a,b,c,d

# function as criterion 
letters %i% (fixed("a") | fixed("z")) # a, z

1:4 %e% 4:5   # 1, 2, 3, 5

1:2 %r% 2     # 1, 2, 1, 2

Run the code above in your browser using DataLab