Every operation is function
Every operator in R, such as +
is a function. Therefore, you can have:
> `+`(8,5)
[1] 13
> mapply(`*`, 1:4, 4:1)
[1] 4 6 6 4
Also, you can define your custom operator, which must be wrapped by %
:
> `%@@%` <- function(a,b){ c(a,b) }
> 4 %@@% 7
[1] 4 7
And you can use operator with %>%
operator in magrittr package (which is usually imported when loading dplyr package):
> 5 %>% `+`(4) %>% `*`(3)
[1] 27
Tags:
R,