Sign in with Microsoft
Sign in or create an account.
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

For replacing all NA values by zero or other content it is necessary to transform data from an input data set to an output data set using function 


A sample script for replacing all NA in xdf file "AirlineDemoSmall.xdf" is shown below:

# Create a data frame with missing values
myDataF <- data.frame(x = rnorm(100), y = runif(100), z = rgamma(100, shape = 2))
xmiss <- = 5, to = 100, by = 5)
ymiss <- = 2, to = 100, by = 5)
myDataF$x[xmiss] <- NA
myDataF$y[ymiss] <- NA

# Convert into a xdf


writeLines("\n\nXdf Generated with random NA values")
print(rxGetInfo(myDataF, n = 15)$data)     # Test ouput data 
## Use from here if there is an existing xdf.
## replace myDataNA with your xdf file
writeLines("\n\nVariables that contains NA values (Missing Observations)")
(mySum <- rxSummary(~., data = myDataNA)$sDataFrame)

# Find variables that are missing
transVars <- mySum$Name[mySum$MissingObs > 0]
print(transVars) #Test detected variables

# create a function to replace NA vals with mean
NAreplace <- function(dataList) {
        replaceFun <- function(x) {
              x[] <- replaceValue
 dataList <- lapply(dataList, replaceFun)
myDataRMV<-file.path(getwd(),"myDataRMV.xdf")       # Replace Missing Value 
trsfxdf<- rxDataStep(inData = myData1, outFile = myDataRMV,
     transformFunc = NAreplace, 
     transformVars = transVars,
     transformObjects = list(replaceValue = "REPLACED MISSING VALUE"),
writeLines("\n\nTransformed xdf with NA replaced by Value")
print(rxGetInfo(myDataRMV, n=15)$data)     # Test output data

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!