Method chaining with R

前端 未结 4 1422
一生所求
一生所求 2021-02-20 14:19

Is it possible to chain functions in R?

Sample data:

m <- matrix(c(1:10, 11:20), nrow = 10, ncol = 2)

For example, I would like to r

4条回答
  •  失恋的感觉
    2021-02-20 14:55

    I would use the magrittr package. It has a "pipe" operator that takes the result of one function and passes it in as an argument to the next:

    m <- matrix(c(1:10, 11:20), nrow = 10, ncol = 2)
    
    m %>% mean %>% sum
    

    Ceci n'est pas un pipe!

提交回复
热议问题