Skip to content
Prev 312872 / 398502 Next

question about sum of (column) elements in R

Hi,

You can follow this example:

test <- structure(list(V1 = c(0L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L), V2 = c(12L, 10L, 4L, 6L,
7L, 13L, 21L, 23L, 20L, 18L, 17L, 16L, 27L, 33L, 11L, 8L, 19L,
16L, 9L)), .Names = c("V1", "V2"), class = "data.frame", row.names = 
c(NA,-19L))

tapply(grid1$V2, grid1$V1, sum)

   0   1   2   3   4
  12  40  64 111  63

HTH
Pascal


Le 04/12/2012 16:59, T Bal a ?crit :