Closed lluisfortes1 closed 4 years ago
The basic use of filter() works as expected:
sp1 = 'virginica' filter(iris, Species == sp1)
But when I want to create a list based on the factor level Species, it fails
sp2 = levels(iris$Species) lapply(sp2, function(x) { filter(iris, Species == x) })
Same if factor is used as character variable:
sp3 = unique(as.character(iris$Species)) lapply(sp3, function(x) { filter(iris, Species == x) })
When using with dplyr, it's working correctly:
lapply(sp2, function(x) { dplyr::filter(iris, Species == x) }) lapply(sp3, function(x) { dplyr::filter(iris, Species == x) })
Good spot, I'll take a look
For now you can use
split(iris, iris$Species)
But I will see if I can come up with something.
The basic use of filter() works as expected:
But when I want to create a list based on the factor level Species, it fails
Same if factor is used as character variable:
When using with dplyr, it's working correctly: