[R] Data frame with Factor column missing data change to NA

Bill Poling Bill@Poling @ending from zeli@@com
Wed Jun 13 16:47:54 CEST 2018


Good morning.

#I have df with a Factor column called "NonAcceptanceOther" that contains missing data.

#Not every record in the df is expected to have a value in this column.

# Typical values look like:
# ERS
# Claim paid without PHX recommended savings
# Claim paid without PHX recommended savings
# MRC Amount
# MRC Amount
# PPO per provider
#Or they are missing (blank)

#Example

df2 <- df[,c("PlaceOfService","ClaimStatusID","NonAcceptanceOther","RejectionCodeID","CPTCats","RevCodeCats","GCode2","ClaimTypeID")]
head(df2, n=20)

   PlaceOfService ClaimStatusID                         NonAcceptanceOther RejectionCodeID          CPTCats     RevCodeCats GCode2 ClaimTypeID

1              11             2                                                         NA          ResPSys NotValidRevCode      2           2

2              81             3                                                         53       PathandLab NotValidRevCode      2           2

3              11             3                                                         47         Medicine NotValidRevCode      1           2

4              09             2                                                         NA           NotCPT NotValidRevCode      1           2

5              11             2                                                         NA        Radiology NotValidRevCode      2           2

6              23             2                                                         NA       MusculoSys NotValidRevCode      2           2

7              12             3                                                         47           NotCPT NotValidRevCode      2           2

8              12             2                                                         NA         Medicine NotValidRevCode      2           2

9              11             3                                                         47         Medicine NotValidRevCode      1           2

10             21             2                                                         NA       Anesthesia NotValidRevCode      2           2

11             11             3                                        ERS              30      EvalandMgmt NotValidRevCode      2           2

12             81             2                                                         NA       PathandLab NotValidRevCode      2           2

13             21             2                                                         NA        Radiology NotValidRevCode      1           2

14             11             2                                                         NA         Medicine NotValidRevCode      1           2

15             99             3 Claim paid without PHX recommended savings              30 CardioHemLympSys             Lab      0           1

16             99             3 Claim paid without PHX recommended savings              30       PathandLab             Lab      0           1

17             99             3                                 MRC Amount              30           NotCPT          Pharma      2           1

18             99             3                                 MRC Amount              30       PathandLab             Lab      2           1

19             81             2                                                         NA       PathandLab NotValidRevCode      2           2

20             23             2                                                         NA         IntegSys NotValidRevCode      1           2

#I would like to set these missing to NA and have them reflected similarly to an NA in a numeric or integer column if possible.

#I have tried several approaches from Googled references:

NonAcceptanceOther <- df$NonAcceptanceOther
table(addNA(NonAcceptanceOther))

is.na <- df$NonAcceptanceOther

df[NonAcceptanceOther == '' | NonAcceptanceOther == 'NA'] <- NA

#However, when I go to use:

missingDF <- PlotMissing(df)

#Only the columns that are numeric or integer reflect their missing values (i.e. RejectionCodeID)  and this "NonAcceptanceOther" column does not reflect or hold the NA values?

Thank you for any advice.

WHP












Confidentiality Notice This message is sent from Zelis. ...{{dropped:16}}



More information about the R-help mailing list