replyr_apply_f_mapped: Apply a function to a re-mapped data frame.

Description Usage Arguments See Also Examples

View source: R/renameRestrictCols.R

Description

Apply a function to a re-mapped data frame.

Usage

1
2
replyr_apply_f_mapped(d, f, nmap, ..., restrictMapIn = FALSE,
  rmap = replyr::replyr_reverseMap(nmap), restrictMapOut = FALSE)

Arguments

d

data.frame to work on

f

function to apply.

nmap

named list mapping with keys specifying new column names, and values as original column names.

...

force later arguments to bind by name

restrictMapIn

logical if TRUE restrict columns when mapping in.

rmap

reverse map (for after f is applied).

restrictMapOut

logical if TRUE restrict columns when mapping out.

See Also

let, replyr_reverseMap, replyr_mapRestrictCols

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# an external function with hard-coded column names
DecreaseRankColumnByOne <- function(d) {
  d$RankColumn <- d$RankColumn - 1
  d
}

# our example data, with different column names
d <- data.frame(Sepal_Length=c(5.8,5.7),
                Sepal_Width=c(4.0,4.4),
                Species='setosa',rank=c(1,2))
print(d)


# map our data to expected column names so we can use function
nmap <- c(GroupColumn='Species',
          ValueColumn='Sepal_Length',
          RankColumn='rank')
print(nmap)

dF <- replyr_apply_f_mapped(d, DecreaseRankColumnByOne, nmap)
print(dF)

replyr documentation built on Nov. 1, 2019, 7:49 p.m.