samedi 26 mai 2018

Check if date is there then update 0 otherwise update amount in R?

First of all sorry for incorrect formatting , actually this is my first question,

I have a following dataset

In this new_effective_ upto is date in posixct format

And amount is in integer

I want to do

if new_effective_upto is NA then update new_amount to amount

if new_effective_upto contains any date then updated new_amount to 0

actually i m not able to compare date in ifelse statment??

What i have done

First i apply substr to extract some part of date & then convert it to integer & then apply ifelse

substr(chart_fixed_rent_recovery_1$new_effective_upto,1,4)

as.integer(chart_fixed_rent_recovery_1$sub_upto)

ifelse(chart_fixed_rent_recovery_1$sub_upto == 'NULL',chart_fixed_rent_recovery_1$AMOUNT,0)

but this does not update amount in any field it only update 0 ??

Dataframe name chart_fixed_rent_recovery_1

Aucun commentaire:

Enregistrer un commentaire