In the following data frame, I need to take the mean of all values in a, b , c
values <- data.frame(value = c("a", "a", "a", "a", "a",
"b", "b", "b",
"c", "c", "c", "c"), i = c(1,2,3,4,5,6,7,8,9,10,11,12))
To achieve this, I tried using aggregate
function as follows:
agg <- aggregate(values, by = list(values$value), FUN = mean)
The output does result in the mean values of i
but I do not think this is the correct way. The output also throws a couple of warnings.
Warning messages:
1: In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
2: In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
3: In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
> agg
Group.1 value i
1 a NA 3.0
2 b NA 7.0
3 c NA 10.5