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

Error with filter() when using lapply() #1

Open
lluisfortes1 opened this issue Apr 15, 2020 · 2 comments
Open

Error with filter() when using lapply() #1

lluisfortes1 opened this issue Apr 15, 2020 · 2 comments

Comments

@lluisfortes1
Copy link

I want to indicate, I've found both tidyft and poorman package throws the same error with the same calculus

The basic use of filter() works as expected:

library(tidyft)
a = as.data.table(iris)

sp1 = 'virginica'
filter(a, Species == sp1)

But when I want to create a list based on the factor level Species, it fails

sp2 = levels(a$Species)

lapply(sp2, function(x) {
  filter(a, Species == x)
})

Same if factor is used as character variable:

sp3 = unique(as.character(a$Species))

lapply(sp3, function(x) {
  filter(a, Species == x)
})

When using with dplyr, it's working correctly:

lapply(sp2, function(x) {
  dplyr::filter(a, Species == x)
})

lapply(sp3, function(x) {
  dplyr::filter(a, Species == x)
})
@hope-data-science
Copy link
Owner

hope-data-science commented Apr 15, 2020

Thank you for reporting, for this case, please use:

library(tidyft)

a = as.data.table(iris)

split(a,by = "Species")

@lluisfortes1
Copy link
Author

Awesome!! Thanks for your work

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