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
There are some variables that will remain as is (here only ID) and some that will be transformed to long format (here all other variables, all ending with _1, _2 o _7)
It has the advantage of using only melt, and not dcast.
But it only works if every letter has the same number of variation numbers. If not, we get the error
Warning message:
In split.default(measurevars, split_on) :
data length is not a multiple of split variable
and many cases are just dropped. I guess is because this method relies on building a list and expects all the elements to have the same length.
Another problem with this method is it doesnt use the right names if we were using longer numbers
I've already asked this question but not received a working answer
https://stackoverflow.com/questions/41163500/r-transform-from-wide-to-long-without-sorting-columns/41163691#41163691
I would like to convert a data.table from long to wide format.
For example this simple data.table.
There are some variables that will remain as is (here only ID) and some that will be transformed to long format (here all other variables, all ending with _1, _2 o _7)
The method I was using to do it is:
But it has a small problem, it reorders the columns alphabetically even if you don't want to.
Wouldn't it be better if dcast just keeps the original order?
Somebody there, mtoto, suggested to do it using factors, splitting the data and using melt.
It has the advantage of using only melt, and not dcast.
But it only works if every letter has the same number of variation numbers. If not, we get the error
and many cases are just dropped. I guess is because this method relies on building a list and expects all the elements to have the same length.
Another problem with this method is it doesnt use the right names if we were using longer numbers
The text was updated successfully, but these errors were encountered: