tidyft
tidyft copied to clipboard
Error with filter() when using lapply()
trafficstars
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)
})
Thank you for reporting, for this case, please use:
library(tidyft)
a = as.data.table(iris)
split(a,by = "Species")
Awesome!! Thanks for your work