Is it possible to somehow combine the function R sprintf (fmt, ...) with a list or data.frame instead of individual vectors?
For example, what I want to achieve:
df <- data.frame(v1 = c('aa','bb','c'), v2 = c('A', 'BB','C'), v3 = 8:10, stringsAsFactors = FALSE) sprintf('x%02s%02s%02i', df[[1]], df[[2]], df[[3]]) [1] "xaa A08" "xbbBB09" "xc C10"
but with more concise syntax, for example:
sprintf('x%02s%02s%02i', df) Error in sprintf("x%02s%02s%02i", df) : too few arguments
In my real situation, I still have many columns to feed sprintf, which makes the code ugly.
I think that in general, the question is how to get around the ellipsis function ...
I am sure that this is not the first to ask about this, but I could not find anything in this direction.
source share