Q:

How can i count the numbers in every subset?

I have several subset like this 
s1 <- c(0,-1,0)  
s2 <- c(0,1,0) 
s3 <- c(0, 1, 2, 1, 2, 1, 2)

If I want to count the number"-4" 
 for example 
"-4"doesn't show up in s1 ,freq=0;

"-4"doesn't show up in s2 ,freq=0;

"-4"doesn't show up in s3 ,freq=0;

It should be reveal that frequency=0
instead
for example 
"1"doesn't show up in s1 ,freq=0;

"1"does show up in s2 ,freq=1;

"1"does show up in s3 ,freq=2;

What can i do that i can get the frequency?? 

A:

Make a list then use lapply
MyList <- list("s1"=s1, "s2"=s2, "s3"=s3)
lapply(MyList,function(x) length(x[x == -4])

The result is a list with the count of -4 for each list element
You can replace lapply with sapply if you want a vector of counts instead of a list, this can be useful if you want the total count instead of the per element count.

