I'm just getting started with pipes
How can I make ifelse()
work with pipes
Here is an example code that works
x <- sample(-5:5,10,replace = T)
x
[1] 0 0 2 -1 1 3 1 3 4 -2
ifelse( sign(x) >= 0,1,-1)
[1] 1 1 1 -1 1 1 1 1 1 -1
Here is my unsuccessful attempt to do it with pipes
x |> sign() |> ifelse(. >= 0, 1, -1)
Error in ifelse(sign(x), . >= 0, 1, -1) : unused argument (-1)