rreporters

ReporteRs Character NAs Blank


I would like to make a FlexTable that makes NA values appear as NA. When the column is of class numeric, I am able to do this. When the column is of class character, the cell appears empty. Is there a way to get my NA values to appear when they are part of a column of class character? I am aware that I could simply replace them with "NA", but I would strongly prefer not to do this.

library(ReporteRs)

y <- data.frame(var.1 = as.character(letters[1:5]), 
                var.2 = as.numeric(1:5), 
                stringsAsFactors = FALSE)
y[3, 1] <- NA
y[4, 2] <- NA

FlexTable(y)

Solution

  • You can add quotes around NA values.

    library(ReporteRs)
    
    y <- data.frame(var.1 = as.character(letters[1:5]), 
                    var.2 = as.numeric(1:5), 
                    stringsAsFactors = FALSE)
    y[3, 1] <- "NA"
    y[4, 2] <- "NA"
    
    FlexTable(y)