this question is a follow up from function doesn't work in R ("argument is not numeric or logical")
I fixed the code for the 'calcBetweenGroupsVariance' function outlined in this textbook by using the aforementioned thread. I am now onto the next stage, where you need to calculate the separation achieved by a variable. This is the code:
calcSeparations <- function(variables,groupvariable) {
# find out how many variables we have
variables <- as.data.frame(variables)
numvariables <- length(variables)
# find the variable names
variablenames <- colnames(variables)
# calculate the separation for each variable
for (i in 1:numvariables)
{
variablei <- variables[i]
variablename <- variablenames[i]
Vw <- calcWithinGroupsVariance(variablei, groupvariable)
Vb <- calcBetweenGroupsVariance (variablei, groupvariable)
sep <- Vb/Vw
print(paste("variable",variablename,"Vw=",Vw,"Vb=",Vb,"separation=",sep))
}
}
calcSeparations(wine[2:14],wine[1])
It comes up with the same error again - that the data is not numeric, even though it is. Any help would be appreciated. Please let me know if I have not provided enough information - I am new to stackoverflow. Thanks!