To count unique values, you can use the table function that creates a frequency table to calculate the occurrences of unique values of a variable.
The table() function generates an object of the table class.
For example:
data(iris)
freq.table <- table(iris$Species)
head(freq.table)
setosa versicolor virginica
50 50 50
In your case:
v = rep(c(1,2, 2, 2), 25)
table(v)
v
1 2
25 75
To convert the table to a data frame:
as.data.frame(table(v))
v Freq
1 1 25
2 2 75
A one-line approach:
as.data.frame(table(v))[,2]
[1] 25 75
If you want to explore more in R programming then watch this R programming tutorial for beginner: