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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -