I am trying to calculate the mean, sd and se of the frequency of several species over the number sites per habitat. I have three sites per habitat and four habitat types, so twelve sites in total. My dataset looks like this
Site Species Habitat Count
A X Wetland 3
B T Urban 12
B U Forest 18
C Z Grassland 3
C Z Grassland 6
My issue is, not all species are recorded in each site and I am getting NA values when I run the code and the mean is not calculating correctly because not all species were recorded in each site (N)
cdata <- ddply(df, c("Species", "Habitat"), summarise,
N = sum(Count),
mean = mean(Count),
sd = sd(Count),
se = sd / sqrt(N))
I have tried using mutate rather than summarise to set N to 3, the number of sites per habitat but I am still getting NA value for SD and SE