integer_counts: Count integer values

View source: R/describing.R

integer_countsR Documentation

Count integer values

Description

Giver a vector of integer values, the function counts the number of data for each integer value included within the span of values.

Usage

integer_counts(x, x.min = min(x), x.max = max(x), perc = FALSE, na.keep = TRUE)

Arguments

x

Numeric vector of integers.

x.min

Minimum observable value.

x.max

Maximum observable value.

perc

Logical value which specifies if convert the counts in percentages.

na.keep

Logical value which specifies if consider missing data when converting counts in percentages (see details).

Details

The function is similar to table, but: 1) it returns a vector; 2) it returns the counts for all values included in the range, considering also the values which not compare in the input vector; 3) it can convert directly counts in percentages (perc=T).

When perc=T, if na.keep=T, in the calculus of percentages missing data will be counted. For this reason, if missing data are present in the vector of responses, the resulting sum of percentages will be lower to 100. The percentages will be calculated dividing the counts for n-q, where q is the number of missing data.

Value

A vector containing the frequencies.

See Also

table

Examples

# Example with 0-frequency
x <- c(5,2,1,2,5,2,4,5,4,4,2,1,2,1,4,4,4,1,2,4)
table(x)
integer_counts(x,1,5)
# Example with NA's
x <- c(5,4,2,5,4,2,1,NA,4,3,4,1,5,3,NA,3,3,2,4,3)
integer_counts(x,1,5)
integer_counts(x,1,5, perc=TRUE)
prop.table(table(x, useNA="always"))*100
integer_counts(x,1,5, perc=TRUE, na.keep=FALSE)
prop.table(table(x))*100

DavideMassidda/testing documentation built on Oct. 12, 2023, 4:32 p.m.