magrittr

Using the %>% pipe, and dot (.) notation

微笑、不失礼 提交于 2019-11-26 06:37:31
问题 When using map on a nested data_frame, I do not understand why the latter two version give an error, how should I use the dot ( . )? library(tidyverse) # dummy data df <- tibble(id = rep(1:10, each = 10), val = runif(100)) df <- nest(df, -id) # works as expected map(df$data, min) df %>% .$data %>% map(., min) # gives an error df %>% map(.$data, min) # Error: Don\'t know how to index with object of type list at level 1 df %>% map(data, min) 回答1: The problem isn't map , but rather how the %>%

What does %>% mean in R [duplicate]

隐身守侯 提交于 2019-11-26 02:42:18
问题 This question already has an answer here: What does %>% function mean in R? 4 answers I am following this example, the server.R , file is here. I plan to do a similar filter, but am lost as to what %>% does. # Apply filters m <- all_movies %>% filter( Reviews >= reviews, Oscars >= oscars, Year >= minyear, Year <= maxyear, BoxOffice >= minboxoffice, BoxOffice <= maxboxoffice ) %>% arrange(Oscars) 回答1: The infix operator %>% is not part of base R, but is in fact defined by the package magrittr