r - Warning message: In mean.default(filtermyData$sulfate, na.rm = TRUE) : argument is not numeric or logical: returning NA -


i writing function load several csv files in single data frame. filter out rows depending on particular value in column id.

i intend find mean of column sulfate/nitrate out of filtered data frame. error mentioned in title.

my code is,

function(directory,pollutant,id=1:332) {     wd<-getwd()     if(wd %in% "c:/users/hp/documents/specdata")     {}     else     {         setwd(directory)     }     temp<-list.files(pattern="*.csv")     mydata<- lapply(temp,read.csv)     filtermydata<-subset(mydata,mydata$id %in% id)     if(pollutant %in% "sulfate")     {         meansulfate<-mean(filtermydata$sulfate,na.rm=true)         meansulfate     }     else     {         meannitrate<-mean(filtermydata$nitrate,na.rm=true)         meannitrate     } } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -