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
id X1_mean_2007 X1_sd_2007 X1_mean_2008 X1_sd_2008 X1_mean_2009 X1_sd_2009
1: 1 12007.1 NA 12008.1 NA NaN NA
2: 2 NaN NA 22008.1 NA 22009.1 NA
Related Issues
There are related issues which deal with naming of output columns in first place but not with order #1153 #1951
(Note, I am happy with the current naming convention)
Output of sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
library(data.table)
data.table 1.10.5 IN DEVELOPMENT built 2018-01-23 05:02:02 UTC; appveyor
The text was updated successfully, but these errors were encountered:
jangorecki
changed the title
[Request] Optionally order columns of multiple value.var in dcast() grouped by RHS
Optionally order columns of multiple value.var in dcast() grouped by RHS
Sep 21, 2019
UweBlock
changed the title
Optionally order columns of multiple value.var in dcast() grouped by RHS
Optionally order columns of multiple value.var in dcast() grouped by RHS of formula
Oct 9, 2021
UweBlock
changed the title
Optionally order columns of multiple value.var in dcast() grouped by RHS of formula
Optionally order columns of multiple value.var in dcast() by RHS of formula
Oct 9, 2021
This brings me the idea to use patterns in addition to colorder = "value.var" (the default) or colorder = "rhs". So, we might have something like colorder = pattern(..., regex)
where regex is a regular expression with groups (in parantheses) and ... giving the order to sort the columns.
Perhaps, this feature might better become an enhancment of setcolorder()?
Giving a second thought, something like colorder = forderv(c("year", "X2", "X1")) or colorder = forderv(c("year", "value.var"))
could work as well, e.g.,
When reshaping multiple value.vars from long to wide format with
dcast()
, the columns are ordered such that the value.vars are grouped together, e.g.,There are some questions on SO which expect the order of columns to be grouped by the RHS:
Reshape data within groups - groups in a single row
How to reshape tabular data to one row per group
There is no option in
dcast()
yet which allows to specify the order of reshaped columns.Workaround
As a workaround, the column order can be rearranged using
setcolorder()
but this requires a lot of manual coding:Now, the columns are order by the RHS (
year
). However, every change to the formula requires to amend the code to reorder the columns:Also, with a list of functions:
Related Issues
There are related issues which deal with naming of output columns in first place but not with order
#1153
#1951
(Note, I am happy with the current naming convention)
Output of sessionInfo()
The text was updated successfully, but these errors were encountered: