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

Jim Lemon
2018-06-14T00:30:13Z

Hi Bill,
It may be that the NonAcceptanceOther, being a character value, has ""
(0 length string) rather than NA. You can convert that to NA like
this:

df2$NonAcceptanceOther[nchar(df2$NonAcceptanceOther) == 0]<-NA

Jim


On Thu, Jun 14, 2018 at 12:47 AM, Bill Poling <Bill.Poling at zelis.com>
wrote:
> 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}}
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.