Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Replace value in a column with 'blank' if it matches the value in another column

$
0
0

I have a following data set as a data frame within R

article_number   1st_cutoff_date   2nd_cutoff_date

abc                12/01/2019       01/14/2020

def                02/10/2020       02/10/2020

What I want to do is in cases where 1st_cutoff_date == 2nd_cutoff_date, then replace 2nd_cutoff date with blank value "". So in the second case 'def' then 2nd_cutoff_date would be blank ""

the data frame is of factors and there are NA's - I have converted to character and tried the following:

AAR_FTW_Final_w_LL[AAR_FTW_Final_w_LL$`1st_Booking_Deadline` == AAR_FTW_Final_w_LL$`2nd_Booking_Deadline`, c("2nd_Booking_Deadline")] <- ""

&

ind<- AAR_FTW_Final_w_LL$`1st_Booking_Deadline` == AAR_FTW_Final_w_LL[`2nd_Booking_Deadlilne`]
AAR_FTW_Final_w_LL[ind, c("2nd_Booking_Deadline")] <- ""

Both return the error:

Error in AAR_FTW_Final_w_LL$`1st_Booking_Deadline` : 
  $ operator is invalid for atomic vectors

I have tried replacing the $ with [] but then I get the error that one of the columns is missing. Is there any easier way to do to this task?


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>