I was hoping someone could help me with the following problem:
I am attempting to make a combined barplot showing the mean and standard errors for 3 different continuous variables (body temp, length, mass) recorded for a binary variable (gender).
I have been able to plot the mean values for each variable but I can't seem to successfully calculate the standard error for these 3 variables using any of the codes I've tried. I tried many things, but I think I was on the right track with this:
View(test4)
test4 <- aggregate(test4,
by = list(Sex = test4$Sex),
FUN = function(x) c(mean = mean(x), sd = sd(x),
n = length(x)))
test4
#this produced mean, sd, length for ALL variables (including sex)
test4<-do.call(test4)
test4$se<-test4$x.sd / sqrt(test4$x.n)
Then I kept getting the error:
Error in sqrt(test4$x.n) : non-numeric argument to mathematical function
I tried to recode to target my 3 variables after aggregate(test4...) but I couldn't get it to work...Then I subsetted by resulting dataframe to exclude sex but that didn't work. I then tried to define it as a matrix or vector but still that didn't work.
I would like my final graph to to have y axis = mean values, x axis = variable (3 sub-groups (Tb, Mass, Length) with two bars side by side showing male and female values for comparison.
Any help or direction anyone could provide would be greatly appreciated!!
Many thanks in advance! :)