I am confused how do.call works.
dat <- data.frame(v1 = c("a", "a", "b", "b"),
v2 = c("a", "b", "a", "b"),
stringsAsFactors = FALSE)
Why does this seem to go one line at a time
do.call(paste, dat)
[1] "a a" "a b" "b a" "b b"
But it is not
do.call(function(x) paste(x), dat)
Error in (function (x) :
unused arguments (v1 = c("a", "a", "b", "b"), v2 = c("a", "b", "a", "b"))
The function I want to use is
paste_ <- function(x) paste(unique(sort(x)), collapse = "_")
I understand that I can just use applyit to get what I want, but I tried to understand what I was doing do.call.
apply(vars_comb, 1, paste_)
source
share