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

patterns() did not consider the position of provided cols in the original DT #6498

Open
hongyuanjia opened this issue Sep 15, 2024 · 0 comments

Comments

@hongyuanjia
Copy link
Contributor

Please see the MRE below. patterns() returns the matched positions of input cols, which are 1 and 2, resulting using id_1 and id_2 as the measure.vars:

library(data.table)

dt <- data.table(
    id_1 = 1:3,
    id_2 = letters[1:3],
    letter_1 = LETTERS[1:3],
    letter_2 = LETTERS[4:6]
)

melt(dt, measure.vars = patterns("_\\d$", cols = paste0("letter_", 1:2)))
#> Warning in melt.data.table(dt, measure.vars = patterns("_\\d$", cols =
#> paste0("letter_", : '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.
#>    letter_1 letter_2 variable  value
#>      <char>   <char>   <fctr> <char>
#> 1:        A        D     id_1      1
#> 2:        B        E     id_1      2
#> 3:        C        F     id_1      3
#> 4:        A        D     id_2      a
#> 5:        B        E     id_2      b
#> 6:        C        F     id_2      c
@hongyuanjia hongyuanjia changed the title patterns() did not consider the position of cols provided in the original DT patterns() did not consider the position of provided cols in the original DT Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant