Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: in dcast, with multiple value.var and a single fun.agg, don't put the fun in the col names #1810

Closed
franknarf1 opened this issue Aug 12, 2016 · 1 comment
Assignees
Milestone

Comments

@franknarf1
Copy link
Contributor

franknarf1 commented Aug 12, 2016

An example from SO: http://stackoverflow.com/a/38923405/

require(data.table)
data = data.table(
    var1 = c("a","b","c","b","d","e","f"),
    var2 = c("aa","bb","cc","dd","ee","ee","ff"),
    subtype = c("1","2","2","2","1","1","2"),
    type = c("A","A","A","A","B","B","B")
)
f = function(v) paste0(unique(v), collapse = "|")
dcast(data, type ~ subtype, value.var = c("var1", "var2"), fun = f)

#    type var1_f_1 var1_f_2 var2_f_1 var2_f_2
#1:    A        a      b|c       aa bb|cc|dd
#2:    B      d|e        f       ee       ff

The _f_ is somewhat redundant in the new column names. Worse, using an anonymous function, we'd see _function_. It would be preferable to just have names like var1_1, etc.

@arunsrinivasan
Copy link
Member

Could you please add require(data.table) to the code as well? It'd be even easier to copy/paste. Thanks. I've edited it in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants