R adding values to a column -


so want add value column depending on value of column

+--------------------------+---------------- | id         |   name      |    value | 1          |   jim       |       | 1          |   jim       |       | 1          |   ron       |       | 2          |   jim       |       | 2          |   tim       |       | 1          |   jim       |       

as can see have value column , want value 0 if name jim , 1 if name else.

+--------------------------+---------------- | id         |   name      |    value | 1          |   jim       |      0 | 1          |   jim       |      0 | 1          |   ron       |      1 | 2          |   jim       |      0 | 2          |   tim       |      1 | 1          |   jim       |      0 

anything appreciated , thanks

so answer question do:

df$value <- as.integer(df$name != 'jim') 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -