Suppose I have the following data frame data
-
V1 V2
A 3
A 2
A 1
B 2
B 3
C 4
C 3
C 1
C 2
Now I want to extract information of each level, i.e. (A
,B
,C
,D
& E
) of V1
. As an example, if I choose to see the sum of different levels in V2
for each level of V1
, what should be the code?
The output I want is-
V1 V2
A 6
B 5
C 10
I tried lapply
and sapply
but they are not giving the information I want. Of course I tried sapply(data,unique)
which made no sense.
Also, in advance (may be a bit trickier), if I want to see the values in V2
which are unique in all the levels of V1
,how to do it?
Thanks !!