Skip to content
Prev 306316 / 398506 Next

create new column in a DF according to values from another column

Here is another technique to use, especially if you have a long list
of replacement values:
+               , list(c(4, 14, 20), "V2")
+               , list(c(3, 17, 19), "V3")
+               )
+     DF$Station[DF$number %in% i[[1L]]] <- i[[2L]]
+ }
number data Station
1       1    1      V1
2       4    2      V2
3       7    3      V1
4       3    4      V3
5      11    5      V1
6      16    6      V1
7      14    7      V2
8      17    8      V3
9      20    9      V2
10     19   10      V3


On Wed, Sep 26, 2012 at 6:49 AM, jeff6868
<geoffrey_klein at etu.u-bourgogne.fr> wrote: