Learn R Programming

expss (version 0.5.5)

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

Description

  • %a% a(ppends) second argument to first argument.
  • %u% u(nites) 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.
  • %n_d%n(ames) d(iff) - diffs second argument from names of first argument. Second argument could be a function which returns logical value. In this case elements of first argument which names give TRUE will be removed.
  • %n_i%n(ames) i(ntersect) - intersects names of first argument with second argument. Second argument could be a function which returns logical value. In this case elements of first argument which names give FALSE will be removed.
All these functions except %n_d%, %n_i% preserve names of vectors and don't remove duplicates. For %d%, %i%, %n_d%, %n_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
e1 %n_d% e2
e1 %n_i% e2

Arguments

e1
vector (possibly data.frame/matrix/list for %n_d%, %n_i%)
e2
vector (or function for %d%, %i%)

Value

vector (possibly data.frame/matrix/list for %n_d%, %n_i%)

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

# %n_i%, %n_d%

# remove column Species
iris %n_d% "Species" 

# leave only columns which names start with "Sepal"
iris %n_i% perl("^Sepal") 

# leave column "Species" and columns which names start with "Sepal" 
iris %n_i% (perl("^Sepal")|"Species") 

Run the code above in your browser using DataLab