I am trying to create an aggregate table with mean and count from the following data
> sample_data
   sample percent
1       A       5
2       A       2
3       A       3
4       B       7
5       B       7
6       C       4
7       C       3
8       C       2
9       C       3
10      D       5
I use this function
aggregate_sample =aggregate(sample_data[,2], list(sample_data$sample), FUN=function(x) c(mn=mean(x),ln=length(x)))
And from console output, I did get what I want:
> aggregate_sample
  Group.1     x.mn     x.ln
1       A 3.333333 3.000000
2       B 7.000000 2.000000
3       C 3.000000 4.000000
4       D 5.000000 1.000000
However, when I click on the Data for aggregate_sample, I only get this
  Group.1     x
1       A 3.333333
2       B 7.000000
3       C 3.000000
4       D 5.000000
Can anyone help me on how to get the right table results?
 
    