I have two columns in data frame
2010 1
2010 1
2010 2
2010 2
2010 3
2011 1
2011 2
I want to count frequency of both columns and get
Here is a simple base R solution using table() and as.data.frame()
df2 <- as.data.frame(table(df1))
# df2
y m Freq
1 2010 1 2
2 2011 1 1
3 2010 2 2
4 2011 2 1
5 2010 3 1
6 2011 3 0
df2[df2$Freq != 0, ]
# output
y m Freq
1 2010 1 2
2 2011 1 1
3 2010 2 2
4 2011 2 1
5 2010 3 1
Data
df1 <- structure(list(y = c(2010L, 2010L, 2010L, 2010L, 2010L, 2011L,
2011L), m = c(1L, 1L, 2L, 2L, 3L, 1L, 2L)), .Names = c("y", "m"
), class = "data.frame", row.names = c(NA, -7L))