I am trying to find the mean of a column in my df without getting NA errors. However, even though I state na.rm = TRUE, my console keeps giving Warning messages like this: 1: In mean.default(inte, na.rm = TRUE) : argument is not numeric or logical: returning NA

I have tried different methods of column selection like $ and [],but this doesn't seem to be the problem. I am a beginner, but shouldn't na.rm = TRUE, remove al values that are NA?

(as far as I am concerned, you will find the problem in line 8)

pollutantmean <- function(directory,pollutant,id = 1:332){
        means <- c()
        for(i in id){
                x <- paste(getwd(), "/", directory, "/", sprintf("%03d", i), ".csv", sep = "")
                freem <- read.csv(x)
                inte <- freem$pollutant
                means[i] <- mean(inte, na.rm = TRUE)


I expect the code to return the mean of the selected column, without any NA's

1 Answers

Community On

Found out that it concerns an entirely different problem: the subset freem$pollutant appears to be of class 'closure'.

Will ask this question again, but formulated better.