Use the table
function to create tables of counts:
> table(df)
V2
V1 A B
X 1 3
Y 1 1
The table of probabilities is derived from this in a straightforward way:
> table(df) / nrow(df)
V2
V1 A B
X 0.1666667 0.5000000
Y 0.1666667 0.1666667
Or, alternatively, using prop.table
:
> prop.table(table(df))
V2
V1 A B
X 0.1666667 0.5000000
Y 0.1666667 0.1666667