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
Using factor is nice when you want to have ordered your strings, and is being used commonly in plotting libraries/functions. I don't see reason why pivot table should behave differently.
Below example shows that order of levels is ignored. This feature request is about ordering those rows/cols entries according to order of factor levels.
@rlavelli your desired output does not seems to be corresponding to your data. Are you on old R version having different random generator algo? Please include sessionInfo(). Also use of dplyr seems to be irrelevant here, best to strip out unrelated stuff to ensure it is not interferring the process.
Also please provide output of levels(dat$x_cut) and levels(dat$y_cut).
Did you actually install factor-sorters branch? there is some logic change in the package made, it is not only a matter of passing sorter argument. Note that argument does not exist in the branch, there is sorters argument instead.
Thank you for the reply, and sorry to bother.
No I didn't install the actual branch, I was under the impression that the new make_sorters function would suffice. I'll try to give an update about that.
For the sake of completeness, here's the info you asked (in a clean R session).
set.seed(123)
dat <- data.frame(
x = rnorm(30)*10,
y = rnorm(30)*10
)
dat$x_cut = cut(dat$x,5)
dat$y_cut = cut(dat$y,5)
levels(dat$x_cut)
# [1] "(-19.7,-12.2]" "(-12.2,-4.65]" "(-4.65,2.86]" "(2.86,10.4]" "(10.4,17.9]"
levels(dat$y_cut)
# [1] "(-15.5,-8.05]" "(-8.05,-0.617]" "(-0.617,6.82]" "(6.82,14.3]" "(14.3,21.7]"
# sessionInfo()
# R version 3.6.1 (2019-07-05)
I was actually able to fix the sorting problem by adding an increasing number before each cut label in my actual case. Like: "1 (-19.7,-12.2]", "2 (-12.2,-4.65]", "3 (-4.65,2.86]" "4 ..". It's not pretty but it gives the correct result even without the use of sorter.
I'll try to install the full branch update and test it. Again, Thank you.
Your workaround is basically avoiding the problem in the first place. As stated in this issue, alphabetical order is used instead of order of levels, thus adding a prefix number is disabling the issue.
Note that your initial report included x order: (-23.9,-15.2] ... which was probably generated with different random seed set. Updated one looks fine.
To easily install this branch you can use remotes or devtools package.
Activity
nicolaskruchten commentedon Nov 3, 2019
This would have to be passed to the JS layer via
sortersrlavelli commentedon Feb 19, 2020
Hello, I've tried the solution proposed in #106, but in my case it still won't give the correct result. See my example:
I'm running:
Thanks!
jangorecki commentedon Feb 21, 2020
@rlavelli your desired output does not seems to be corresponding to your data. Are you on old R version having different random generator algo? Please include
sessionInfo(). Also use of dplyr seems to be irrelevant here, best to strip out unrelated stuff to ensure it is not interferring the process.will do.
Also please provide output of
levels(dat$x_cut)andlevels(dat$y_cut).Did you actually install
factor-sortersbranch? there is some logic change in the package made, it is not only a matter of passingsorterargument. Note that argument does not exist in the branch, there issortersargument instead.rlavelli commentedon Feb 21, 2020
Thank you for the reply, and sorry to bother.
No I didn't install the actual branch, I was under the impression that the new
make_sortersfunction would suffice. I'll try to give an update about that.For the sake of completeness, here's the info you asked (in a clean R session).
I was actually able to fix the sorting problem by adding an increasing number before each
cutlabel in my actual case. Like:"1 (-19.7,-12.2]", "2 (-12.2,-4.65]", "3 (-4.65,2.86]" "4 ..". It's not pretty but it gives the correct result even without the use ofsorter.I'll try to install the full branch update and test it. Again, Thank you.
jangorecki commentedon Feb 21, 2020
Your workaround is basically avoiding the problem in the first place. As stated in this issue, alphabetical order is used instead of order of levels, thus adding a prefix number is disabling the issue.
Note that your initial report included
x order: (-23.9,-15.2] ...which was probably generated with different random seed set. Updated one looks fine.To easily install this branch you can use
remotesordevtoolspackage.Please report back if you still have a problem even when using this branch.
jangorecki commentedon Feb 26, 2020
@rlavelli any news if the branch address your case?
rlavelli commentedon Feb 29, 2020
I'm sorry for the delay. I've tried the full branch and it works. Thank you!