For a sample dataframe:
df1 <- structure(list(id = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 5L), c.1 = c(21L, 22L, 33L, 43L, 12L, 33L, 21L,
54L, 32L, 45L, 24L, 11L, 5L, 2L, 1L), count = c(15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L)), .Names = c("id",
"c.1", "count"), row.names = c(NA, -15L), class = "data.frame")
I wish to count the number of data points in col.1 BY the id column. For example in the above dataframe, I want a column, 'counts' to be added which records how many rows of data there are for each of the ids i.e. the count column would record 3s for ids 1, 2 and 3 and then 4s for id 4 and 1 for id 5.
I have been trying to use length but I cant seem to include a 'by' type command to look at id.
Any help would be appreciated.