Learn R Programming

wavethresh (version 2.2-3)

compress.default: Compress a (Wavelet) Vector

Description

Compression of a vector by removal of zero elements.

Usage

compress.default(v, verbose=FALSE)

Arguments

v
numeric vector to compress
verbose
logical; if true then report on compression activity.

Value

  • An object of class "compressed" if compression took place, otherwise a an object of class "uncompressed"

RELEASE

Release 2.2 Copyright Guy Nason 1993

BUGS

Sometimes the compressed object can be larger than the original. This usually only happens for small objects, so it doesn't really matter.

Details

Images are large objects. Thresholded 2d wavelet objects (imwd) are also large, but many of their elements are zero. Compress takes a vector, decides whether compression is necessary and if it is makes an object of class "compressed" containing the nonzero elements and their position in the original vector.

The decision whether to compress the vector or not depends on two things, first the number of non-zero elements in the vector (r, say), and second the length of the vector (n, say). Since the position and value of the non-zero elements is stored we will need to store 2r values for the non-zero elements. So compression takes place if 2r < n.

This function is a method for the generic function compress() for class default. It can be invoked by calling compress(x) for an object x of the appropriate class, or directly by calling compress.default(x) regardless of the class of the object.

See Also

compressed.object, uncompressed.object

Examples

Run this code
#
# Compress a vector with lots of zeroes
#
str(compress(c(rep(0,100),99)))
## List of 3
##  $ position       : int 101
##  $ values         : num 99
##  $ original.length: int 101
##  - attr(*, "class")= chr "compressed"

## Try to compress a vector with not many zeroes
compress(1:10)
## (uncompressed)

Run the code above in your browser using DataLab