vectors: Infix operations on vectors - append, diff, intersection,...

vectorsR Documentation

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

Description

All these functions except %n_d%, %n_i% preserve names of vectors and don't remove duplicates.

  • %a% a(ppends) second argument to the first argument. See also append.

  • %u% and v_union u(nite) first and second arguments. Remove elements from the second argument which exist in the first argument.

  • %d% and v_diff d(iff) second argument from the first argument. Second argument could be a function which returns logical value. In this case elements of the first argument which give TRUE will be removed.

  • %i% and v_intersect i(ntersect) first argument and second argument. Second argument could be a function which returns logical value. In this case elements of the first argument which give FALSE will be removed.

  • %e% and v_xor e(xclusive OR). Returns elements that contained only in one of arguments.

  • %r% r(epeats) first argument second argument times. See also rep.

  • %n_d% and n_diff n(ames) d(iff) - diff second argument from names of first argument. Second argument could be a function which returns logical value. In this case elements of the first argument which names give TRUE will be removed.

  • %n_i% and n_intersect n(ames) i(ntersect) - intersect names of the first argument with the second argument. Second argument could be a function which returns logical value. In this case elements of the first argument which names give FALSE will be removed.

For %d%, %i%, %n_d%, %n_i% one can use criteria functions. See criteria for details.

Usage

e1 %a% e2

v_union(e1, e2)

e1 %u% e2

v_diff(e1, e2)

e1 %d% e2

v_intersect(e1, e2)

e1 %i% e2

v_xor(e1, e2)

e1 %e% e2

e1 %r% e2

n_intersect(e1, e2)

e1 %n_i% e2

n_diff(e1, e2)

e1 %n_d% e2

Arguments

e1

vector or data.frame, matrix, list for %n_d%, %n_i%)

e2

vector or function for %d%, %i%

Value

vector or data.frame, matrix, list for %n_d%, %n_i%)

Examples


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% greater(4) # 1:4

1:4 %i% 4:5   # 4

# with criteria functions 
letters %i% (contains("a") | contains("z")) # a, z

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

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% like("Sepal*") 

# leave column "Species" and columns which names start with "Sepal" 
iris %n_i% ("Species" | like("Sepal*")) 
iris %n_i% or("Species", like("Sepal*")) # same result


expss documentation built on July 26, 2023, 5:23 p.m.