-2

i imported a csv file by using read.csv, i checked the data format is 'list' by using mode().

The csv imported file has a column called 'condition' with value: used or new enter image description here

Then i need to add a new column called'Isnew', if the existing column 'condition' is used, then 'Isnew' is 0, otherwise 'Isnew' is 1,

how to achieve that?

Jaap
  • 81,064
  • 34
  • 182
  • 193
Shuo Liu
  • 53
  • 2
  • 7

1 Answers1

0

This should work:

dataTableName$IsNew <- ifelse(dataTableName$Condition == "used", 0, 1)
krish
  • 1,388
  • 2
  • 18
  • 28