Display NA values in excel when using WriteXLS in R
The term NA refers to “No Value is Available”. The NA values in an Excel file are the cells that are left empty( there is no data).
In R Programming, the data in the excel files are manipulated using the xlsx package. The Null (NA) values present in an excel file are displayed by initializing the attribute showNA to TRUE in the write.xlsx() function. By doing this we were storing the Null (NA) value as itself by default it’s stored as Blank space and to check whether NA values are stored and we are displaying the stored data in the excel file using read.xlsx() function.
The xlsx() package is also responsible to manipulate the data in an excel file but the inclusion of the WriteXLS package is done to overcome the drawbacks present in it. Using the writeXLS package we can write one or more data frames into an Excel File which is not possible using the xlsx() package but can be done using xlsx2().
Syntax : write.xlsx(df,path,sheetName,col.names,showNA,password)
- df – data frame to be inserted into Excel file
- path – path to store excel file
- sheetName – The sheet name where the data frame is going to store is specified here
- col.ames – If TRUE the column names of the data frame are inserted as Header in the Excel file and vice versa
- showNA – If TRUE the NA values are stored as NULL only otherwise they are going to store as blank values
- password – Used to protect files by enabling passwords if required.
Steps to be followed
The steps we need to follow to display NA values in excel when using WriteXLS.
- First we need to install the xlsx package and load it.
- We need to initialize the dataframe.
- Later using write.xlsx() function we can inert the data frame into an excel file the attributes of this function are discussed here…
- df – represents the name of the data frame in our code
- sheetName – used to specify the sheet Name when this data frame is go to be inserted(Sheet1 in our code)
- col.names – to make sure the header of data frame are inserted as headings in excel file (TRUE)
- showNA – This attribute is set to TRUE to make sure that all the NULL (NA) values in our data frame are inserted as NULL values instead of inserting them as blank spaces in the excel document.
- Finally we are displaying the data present in an excel file by reading it using xlsx.read() function in xlsx package.
Once the dataset is created, now we can use it to display NA values.
Please Login to comment...