I'm trying to create my own function to compute Coefficient of Variation given any variable (column) within a dataframe. So far I've got the below code
coeffvar <- function(variable)
{
abs((SD(variable) / mean(variable))*100)
}
Which works for single vectors, but when the argument is a dataframe, I get the following error:
Warning message:
In mean.default(variable) :
argument is not numeric or logical: returning NA
and all outputs are NA