magrittr
filter for complete cases in data.frame using dplyr (case-wise deletion)
Try this: df %>% na.omit or this: df %>% filter(complete.cases(.)) or this: library(tidyr) df %>% drop_na If you want to filter based on one variable’s missingness, use a conditional: df %>% filter(!is.na(x1)) or df %>% drop_na(x1) Other answers indicate that of the solutions above na.omit is much slower but that has to be balanced against … Read more
R: use magrittr pipe operator in self written package
It should have worked correctly if you had magrittr listed in Depends. However, this is not advised. Instead, you leave magrittr in Imports and add the following line to NAMESPACE: importFrom(magrittr,”%>%”) I suggest reading Writing R extensions. Your question is covered in paragraphs 1.1.3 and 1.5.1.
What does %>% mean in R [duplicate]
The infix operator %>% is not part of base R, but is in fact defined by the package magrittr (CRAN) and is heavily used by dplyr (CRAN). It works like a pipe, hence the reference to Magritte’s famous painting The Treachery of Images. What the function does is to pass the left hand side of … Read more
What does %>% function mean in R?
%…% operators %>% has no builtin meaning but the user (or a package) is free to define operators of the form %whatever% in any way they like. For example, this function will return a string consisting of its left argument followed by a comma and space and then it’s right argument. “%,%” <- function(x, y) … Read more
R Conditional evaluation when using the pipe operator %>%
Here is a quick example that takes advantage of the . and ifelse: X<-1 Y<-T X %>% add(1) %>% { ifelse(Y ,add(.,1), . ) } In the ifelse, if Y is TRUE if will add 1, otherwise it will just return the last value of X. The . is a stand-in which tells the function … Read more
Using the %>% pipe, and dot (.) notation
The problem isn’t map, but rather how the %>% pipe deals with the .. Consider the following examples (remember that / is a two argument function in R): Simple piping: 1 %>% `/`(2) Is equivalent to `/`(1, 2) or 1 / 2 and gives 0.5. It is also equivalent to 1 %>% `/`(., 2). Simple … Read more