Let say, I have a table named table
with headers which looks like
A B
1 2
2 1
What I want to do is adding a new column table$C
such that
- if
table$A < table$B
thentable$C <- (table$B-table$A)/table$A
- if
table$A > table$B
thentable$C <- (table$B-table$A)/table$B
for each row so that the resulting table would look like
A B C
1 2 1
2 1 -1
I tried, quite naively,
> table$C <- if (table$A < table$B) (table$B-table$A)/table$A else (table$B-table$A)/\table$B
and
> table$C <- ifelse(table$A < table$B, (table$B-table$A)/table$A, (table$B-table$A)/table$B)
but both of them didn't work. How do I do this one?