I want to find out mean of each column in my dataset, which contains null / blank values.
I've attached screenshots of actual and sample data for reference.
I want to find out mean of each column in my dataset, which contains null / blank values.
I've attached screenshots of actual and sample data for reference.
I don't see the data? Usually, you just have to calculate mean() of extracted column from a data frame if a column is numerical. And you become immediate data frame with importing an excel file in rstudio.
It's is easier to work with the data frame if you name your columns.
dataframe_name <- c(column1, column2, column3)
Then, you can easily extract the mean of a column.
mean(dataframe_name$column1)
Best thing to do, is to add a helper column, using this formula:
=IfError(B1;0)
(Obviously you might need to use another cell reference)
This formula replaces all error values by zero, you can use this column as an input for calculating your averages.
There are two simple ways that can solve your problem.
=IfError(Cell;0)
=MEAN(StartCell:EndCell)
0
by using the replace all function and take the mean value afterwards.Note: Both approaches will take into consideration the zeros when calculating the mean. If you want to avoid this, replace the null values with "nothing". Hope that helps.
library(tidyverse)
df %>%
summarise_if(is.numeric, mean, na.rm = TRUE)
This calculates the mean for every numeric column in your dataframe.