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
Post a Comment