r - Subsetting vectors with extract -


imagine have vector, , want remove specific element. following

library(magrittr)  foo <- letters[1:10]  foo %>%  {    bar <- .     bar %>%       extract(bar %>%                equals("a") %>%                not) }   [1] "b" "c" "d" "e" "f" "g" "h" "i" "j" 

but if i'd more succinct, this:

foo %>%    extract(. %>%              equals("a") %>%              not) 

doesn't work:

error in extract(., . %>% equals("a") %>% not) :    invalid subscript type 'closure' 

isn't there more idiomatically magrittr'y way this?

one option pipe foo subsetting function [, limiting elements not equal using !=:

foo %>% "["(. != "a") # [1] "b" "c" "d" "e" "f" "g" "h" "i" "j" 

the magrittr package has aliased [ extract, equivalent to:

foo %>% extract(. != "a") # [1] "b" "c" "d" "e" "f" "g" "h" "i" "j" 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -