mardi 31 juillet 2018

Error during sorting two columns in a dataframe

So I am trying to sort two columns in my two dataframes (rdw_n and rdw_p) and then trying to append them, the columns are ACCT_NUM and acct_purged_dt. The issue is, my input file contains acct_purged dt, but all acct_purged dt are blank, so When I try to sort them using below code .

rdw_n> rdw_n[with(rdw_n, order(rdw_n$ACCT_NUM, rdw_n$acct_purged_dt)), ]

This throws an error as "Error in order(rdw_n$ACCT_NUM, rdw_n$acct_purged_dt) : argument 2 is not a vector", So I can assume that this issue is occuring due to all null values in acct_purged_dt.

So I tried another approach where I an checking at the start if the acct_purged_dt is not null then do the above operation else append the dataframes.This is the code I am using

ifelse(!is.na(rdw_n$acct_purged_dt),rdw_n<- rdw_n[with(rdw_n, order(rdw_n$ACCT_NUM, rdw_n$acct_purged_dt)), ],rdw_pn <-rbind(rdw_n,rdw_p))

still the issue comes as : In is.na(rdw_n$acct_purged_dt) : is.na() applied to non-(list or vector) of type 'NULL'

What can be the resolution for this ?

Aucun commentaire:

Enregistrer un commentaire