I have a dataframe --> "test"
> test
V1 V2
1 INS01 1
2 INS01 1
3 INS02 1
4 INS03 2
5 INS03 3
6 INS04 4
> class(test)
[1] "data.frame"
I wanted a count of "INS01", "INS02", "INS03", "INS04". I tried using "by" but it is not giving me the desired output.
> agg <- by(test, test$V1, function(x) length(x))
> agg
test$V1: INS01
[1] 2
------------------------------------------------------------
test$V1: INS02
[1] 2
------------------------------------------------------------
test$V1: INS03
[1] 2
------------------------------------------------------------
test$V1: INS04
[1] 2
I am stuck here. Any help is appreciated. thanks