The main way of counting the amount of what you have is to sum the logical vector, where each element of the logical vector is 1 if the source element is the thing you want to count, or 0 otherwise,
Let's start with some data:
N = 1000 set.seed(2) DF <- data.frame(NAME=as.character(1:N), YEAR=sample(c("Freshman","Sophomore","Junior","Senior"), size=N, replace=T), MAJOR=sample(c("BIO","ECON","HIST","LIT","MATH"),size=N, replace=T, prob=c(.20, .15, .30, .30, .05)), GPA=runif(N, min=0, max=4))
This way we find out how many BIO majors you have:
sum(DF$MAJOR=="BIO") [1] 181
If you want to know how much you have for each existing major, can you get a list of majors with ? unique and then apply the function above to the list with ? lapply :
lapply(unique(DF$MAJOR), function(x){ sum(DF$MAJOR==x) })
Here's a slightly more beautiful version:
cbind(levels(unique(DF$MAJOR)), lapply(unique(DF$MAJOR), function(x){ sum(DF$MAJOR==x) })) [,1] [,2] [1,] "BIO" 297 [2,] "ECON" 303 [3,] "HIST" 181 [4,] "LIT" 155 [5,] "MATH" 64
You should be able to take it from here.
Update: @DWin is right, I did it too hard. Since DF$MAJOR is a factor, you can simply do:
> summary(DF$MAJOR) BIO ECON HIST LIT MATH 181 155 297 303 64