I am trying to classify species based on commonness. There are 4 classifications:
- Rare - frequency<mean & relative abundance<mean
- Occasional - frequency<mean & relative abundance>mean
- Common - frequency>mean & relative abundance<mean
- Dominant - frequency>mean & relative abundance>mean
I am trying to create an if else statement to add a column with these classifications to my data frame which looks like
species <- c("a", "b", "c", "d", "e", "f")
relabund <- c(.5, .11, .23, .06, .36, .19) #relative abundance
freq <- c(6, 3, 20, 2, 11, 4) #number of sites species occurs at
df = data.frame(species, relabund, freq)
I've tried something like this:
if (df[,2]>mean(relabund) && df[,3]>mean(freq)) {
df$Classification = "Dominant"
} else if (df[,2]<mean(relabund) && df[,3]<mean(freq)) {
df$Classification = "Rare"
} else if (df[,2]<mean(relabund) && df[,3]>mean(freq)) {
df$Classification = "Common"
} else
df$Classification = "Occasional"
But this doesn't work as it classifies all species as "Rare". I'm very new to if else statements so any help would be appreciated.
Thank you!