-
Notifications
You must be signed in to change notification settings - Fork 990
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
patterns()
did not consider the position of provided cols
in the original DT
#6498
Comments
patterns()
did not consider the position of cols
provided in the original DTpatterns()
did not consider the position of provided cols
in the original DT
Can confirm the MRE, but I wonder if it's by intended design that |
yes it is intended and working as documented in ?patterns:
For this example I would suggest using measure() instead of patterns() > melt(dt, measure.vars=measure(letter, pattern="letter_([12])"))
id_1 id_2 letter value
<int> <char> <char> <char>
1: 1 a 1 A
2: 2 b 1 B
3: 3 c 1 C
4: 1 a 2 D
5: 2 b 2 E
6: 3 c 2 F please close if that is OK for you, or clarify. |
or > melt(dt, measure.vars=measure(value.name, number=as.integer, pattern="(.*)_([12])"))
number id letter
<int> <char> <char>
1: 1 1 A
2: 1 2 B
3: 1 3 C
4: 2 a D
5: 2 b E
6: 2 c F
Message d'avis :
Dans melt.data.table(dt, measure.vars = measure(value.name, number = as.integer, :
'measure.vars' [id_1, id_2] are not all of the same type. By order of hierarchy, the molten data value column will be of type 'character'. All measure variables not of type 'character' will be coerced too. Check DETAILS in ?melt.data.table for more on coercion. |
@tdhock I am totally fine with the |
I don't think cols is meant to be provided. |
I guess it could be supported if we change return value of patterns from indices to names (when cols are names), but in general I think it is better if the user just provides a more expressive regex > melt(dt, measure.vars = patterns("letter"))
id_1 id_2 variable value
<int> <char> <fctr> <char>
1: 1 a letter_1 A
2: 2 b letter_1 B
3: 3 c letter_1 C
4: 1 a letter_2 D
5: 2 b letter_2 E
6: 3 c letter_2 F |
The measure approach is more flexible and featue-rich. If current behavior is the intended behavior, I would suggest either remove the cols parameter or at least document that it is not intended to be used directly to avoid confusing to users. |
I agree, it's redundant to have a second column filter so maybe omit/document (just |
After looking at the patterns code, adding this feature was really simple, and it did not cause any existing tests to break, so I created a PR, #6510, can you please review and tell me if that is a sufficient change in docs/behavior? |
Thanks! I believe #6510 is the right move. |
Please see the MRE below.
patterns()
returns the matched positions of inputcols,
which are1
and2
, resulting usingid_1
andid_2
as themeasure.vars
:The text was updated successfully, but these errors were encountered: