Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: piping (%>%) not working with round(). Ex: 136/13.00 %>% round() = 10.46154

Tags:

rounding

r

piping

why does 136/13.00 %>% round() return 10? The same input without the piper returns the correct value

136/13.00 %>% round()
[1] 10.46154
> round(136/13.00)
[1] 10
10.46154 %>% round()
[1] 10
like image 454
LucasMation Avatar asked Sep 16 '25 13:09

LucasMation


1 Answers

Looks like operator precedence

(136/13) %>% 
          round
#[1] 10

We can also make it a bit more chainy

136 %>%
     `/`(13) %>%
     round
#[1] 10
like image 52
akrun Avatar answered Sep 18 '25 04:09

akrun