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

Feature Request: Naming convention when dcasting against multiple value.var #1153

Closed
MichaelChirico opened this issue May 19, 2015 · 2 comments

Comments

@MichaelChirico
Copy link
Member

Consider this use of dcast, closely related to this SO question of mine:

x<-dcast(data.table(id=rep(6:10,each=3),var1=rnorm(15),var2=runif(15))[,I:=1:.N,by=id],
         id~I,value.var=c("var1","var2"))

Results in:

   id     1_var1     2_var1     3_var1    1_var2    2_var2    3_var2
1:  6  1.1360655 -0.9103166  1.3264121 0.2905829 0.9487390 0.1701081
2:  7 -1.0619713 -0.3614489  0.4775475 0.1998609 0.6483900 0.9961365
3:  8 -0.3320640 -2.0180934  0.2448504 0.6345779 0.3264954 0.2384962
4:  9  1.0172775 -0.4870558 -0.9395609 0.5937144 0.1944799 0.2312313
5: 10  0.2682756  1.1874830 -0.3778297 0.6486127 0.1134069 0.2296220

Having variables that start with a number can be a pain (e.g., dt[,1_var1] is an error), and it's also more natural to have reversed the naming:

setnames(x,paste0(rep(c("var1","var2"),each=3,rep(1:3,2)))

It would be nice for this to be the default naming convention; also note that I raised this question around a year ago (here), but that solution doesn't work here (leads to identical output).

@MichaelChirico
Copy link
Member Author

Thanks Arun!

@arunsrinivasan
Copy link
Member

@MichaelChirico 👍

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