Skip to content
Prev 169850 / 398506 Next

Dataframes: conditional calculations per row .

You can use 'ifelse':
+            ifelse(x$id == 2, 221,
+               ifelse(x$id == 3, 2221, 22221)))
id   cal
1   4 22221
2   1    21
3   3  2221
4   1    21
5   2   221
6   2   221
7   1    21
8   2   221
9   4 22221
10  2   221
11  2   221
12  3  2221
13  2   221
14  1    21
15  4 22221
16  3  2221
17  4 22221
18  1    21
19  3  2221
20  2   221


On Mon, Feb 9, 2009 at 5:11 PM, Jes?s Guillermo Andrade
<jgandradev at mac.com> wrote: