You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
An example from SO: http://stackoverflow.com/a/38923405/
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 likevar1_1
, etc.The text was updated successfully, but these errors were encountered: