Skip to content
Prev 315949 / 398502 Next

summarise subsets of a vector

You didn't indicate what you want to do with the 101st observation. Arun's
solution creates an 11th group and divides by the number in the group(1),
while Jessica's solution creates an 11th column and divides by 10.
1          2          3          4          5          6          7

  0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000

         8          9         10         11 
  0.146375   0.000000   0.194500 100.000000
Warning message:
In matrix(test, nrow = 10) :
  data length [101] is not a sub-multiple or multiple of the number of rows
[10]
[1]  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
 [8]  0.146375  0.000000  0.194500 10.000000

Another approach would be to use aggregate:
Group.1          x
1        1   0.000000
2        2   0.000000
3        3   0.000000
4        4   0.000000
5        5   0.000000
6        6   0.000000
7        7   0.000000
8        8   0.146375
9        9   0.000000
10      10   0.194500
11      11 100.000000

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352