I have a dataframe named 'directory' which has 4 columns namely a,b,c,d. I need to find the mean of either column b or column c based on the input.
Both the columns b and c have NAs and numeric values.
TotalMean<- function(directory, pollutant = "b", id = 1:10)
{
mean(subset(directory, ID= id, select = directory[[pollutant]]), na.rm = TRUE)
}
TotalMean<- function(directory, pollutant = "b", id = 1:10)
{
mean(subset(directory, ID= id, select = directory$pollutant), na.rm = TRUE)
}
TotalMean<- function(directory, pollutant = "b", id = 1:10)
{
mean(subset(directory, ID= id, select = directory[,pollutant]), na.rm = TRUE)
}
I've tried all the above mentioned functions. However it gives me the following error.
Since I'm new to R programming I'm not sure why this is happening. Any help would be appreciated.
Thanks in advance