How to avoid this warning ?

The only way to avoid this warning is to use the mean() function with vectors having numeric values only. For example, In the above example we can calculate the mean of the minor column as it contains numerical values only:

R




# Create a data frame
dataframe <- data.frame(students=c('Bhuwanesh', 'Anil'
                                   'Suraj', 'Piyush'
                                   'Dheeraj'),
                 section=c('A', 'A', 'C', 'C', 'B'),
                 minor=c(87, 98, 71, 89, 82),
                 major=c(80, 88, 84, 74, 70))
  
# Try to calculate mean of values stored 
# at the column minor in the dataframe
mean(dataframe$minor)


Output:

Output

How to Fix in R: Argument is not numeric or logical: returning na

In this article, we are going to see how to fix in R argument is not numeric or logical returning na.

This is the warning message that you may face in R. It takes the following form:

Warning message:

In mean.default(dataframe) : argument is not numeric or logical: returning NA

The R compiler produces such type of error when we try to compute the mean of an object in R but the object contains non-numerical or illogical values. This article focuses on how we can fix this error.

Similar Reads

When this error might occur

Let’s create a data frame first:...

How to avoid this warning ?

...

Mean using sapply() function

...

Contact Us