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

Could dt_select support selection by column names pattern? #9

Closed
hope-data-science opened this issue Jan 13, 2020 · 4 comments
Closed

Comments

@hope-data-science
Copy link

In dplyr, we have iris %>% select(starts_with("Se")).
In maditr, the analogous way is iris %>% dt_select(startsWith(colnames(.),"Se")).

Is there some way to make it more convenient? Such as:
iris %>% dt_select("^Se")
Once receive a character, understand it as a regular expression.

@gdemin
Copy link
Owner

gdemin commented Jan 13, 2020

Good idea, I will definitely implement this in the next release.
If we have character started with ^ or ended with $ then we will expand it to column names. But note that we haven't parametric evaluation in this case:

# dplyr
my_vars = "Se"  
iris %>% select(starts_with(my_vars )) # work

# maditr
my_vars = "^Se"  
iris %>% dt_select(my_vars ) # will not work

@hope-data-science
Copy link
Author

While ^ and $ are good, but dplyr::contains might also be useful. Perhaps provide a new parameter like "regex"?
Thanks.

@gdemin
Copy link
Owner

gdemin commented Jan 13, 2020

You can describe any name with "^" and "$", e. g. "^.*my_string" is equivalent to contains("my_string"). However I will think about general API for variable selectors.

gdemin added a commit that referenced this issue Jan 21, 2020
…pal") -> iris[,c("Sepal.Length", "Sepal.Width")]. No manual yet (issue #9)
@hope-data-science
Copy link
Author

I have tried too, but I could not support Sepal.Length:Petal.Length for select() so far.
See https://hope-data-science.github.io/tidydt/reference/select_dt.html.

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

2 participants