I am trying to calculate means and standard deviations based on groups in a data.frame.
Sample | Widht | Weight | Length |
---|---|---|---|
A1.1 | 3.5 | 6.7 | 5.8 |
8.3 | 4.2 | 6.3 | 5.5 |
A1.1 | 2.9 | 5.7 | 5.1 |
8.3 | 3.7 | 6.1 | 5.4 |
I have been trying with this code to calculate means and standard deviations for each column based on the sample. I have many more columns in the real data frame but all should be calculated based on the sample column.
agdf<- aggregate(d.f, by=list(d.f$sample), function(x) c(mean = mean(x, na.rm=TRUE), sd = sd(x, na.rm=TRUE)))
When I try this command I get this error message :
Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
Calling var(x) on a factor x is defunct.
Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
I have checked classes for each column and the "sample" column is a factor while the others are numeric. I am very new to R and I don´t really understand what is wrong and how I could solve it. I would really appreciate some ideas/help. Thank you.