Imputation in R

0 votes
Is there any package in R which helps to replace NA values in a column with different criteria such as 'mean' of column, 'median' of column, 'maximum' value in column and so on.
Mar 27, 2018 in Data Analytics by Ashish
• 2,630 points
20 views

1 answer to this question.

0 votes

You can work with the "Hmisc" package, which helps you to impute columns.

Let's take this data-frame:

DF <- data.frame(cost = c(10, 20, NA, 40), fruit = c('apple','guava','banana','orange'))

Imputing with mean value:

with(DF, impute(cost, mean))

Imputing with median value:

with(DF, impute(cost, median))

Imputing with random value:

with(DF, impute(cost, 'random'))

Imputing with minimum value:

with(DF, impute(cost, min))

Imputing with maximum value:

with(DF, impute(cost, max))
answered Mar 27, 2018 by Bharani
• 4,550 points

Related Questions In Data Analytics

+1 vote
1 answer

Need a hadoop engine in backend to run r server

Dear Koushik, Hope you are doing great. The hadoop ...READ MORE

answered Dec 17, 2017 in Data Analytics by Sudhir
• 1,610 points
54 views
0 votes
1 answer

How to change y axis max in time series using R?

The axis limits are being set using ...READ MORE

answered Apr 3, 2018 in Data Analytics by darklord
• 6,140 points
104 views
0 votes
1 answer

AUC for 3-Class prediction in R

Use type='probs' inside predict() function, so that ...READ MORE

answered Apr 4, 2018 in Data Analytics by Bharani
• 4,550 points
120 views
0 votes
1 answer
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
127 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
103 views
0 votes
1 answer

Plotting multiple graphs on the same page in R

If you want to plot 4 graphs ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,550 points
50 views
+1 vote
2 answers

Custom Function to replace missing values in a vector with the mean of values

Try this. lapply(a,function(x){ifelse(is.na(x),mean(a,na.rm = TRUE) ...READ MORE

answered Aug 14 in Data Analytics by anonymous
76 views
0 votes
2 answers

Installing MXNet for R in Windows System

You can install it for python in ...READ MORE

answered Dec 3, 2018 in Data Analytics by Kalgi
• 40,480 points
321 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
63 views