Learn R Programming

Rlab (version 4.0)

count: Counts elements which meet specified conditions

Description

Count the number of times the values in the vector meet the specified conditions.

Usage

count(x)

Arguments

x

Vector and condition to count.

See Also

length, nchar

Examples

Run this code
# NOT RUN {
set.seed(1)
x <- rnorm(100)

# Count the number of times the values in x are greater then 0
count( x>0 )

# Count the number of times the values in x are within the 95% confidence interval
count( (x>-1.96) & (x<1.96) )
# Or could have used
count( abs(x)<1.96 )

# Count the number of times the values in x are the same as the first element
count( x==x[1] )
# }

Run the code above in your browser using DataLab