freq: Frequency table

Description Usage Arguments Value See Also Examples

Description

Frequency table of the values of a RasterLayer.

Usage

1
2
3
4
5
## S4 method for signature 'RasterLayer'
freq(x, digits=0, value=NULL, useNA='ifany', progress='', ...)

## S4 method for signature 'RasterStackBrick'
freq(x, digits=0, value=NULL, useNA='ifany', merge=FALSE, progress='', ...)

Arguments

x

RasterLayer

digits

non-negative integer for rounding the cell values. Argument is passed to round

value

numeric, logical or NA. An optional single value to only count the number of cells with that value

useNA

character. What to do with NA values? Options are "no", "ifany", "always". See to table

progress

character to specify a progress bar. Choose from 'text', 'window', or ” (the default, no progress bar)

merge

logical. If TRUE the list will be merged into a single data.frame

...

additional arguments (none implemented)

Value

matrix (RasterLayer). List of matrices (one for each layer) or data.frame (if merge=TRUE) (RasterStack or RasterBrick)

See Also

crosstab and zonal

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
r <- raster(nrow=18, ncol=36)
values(r) <- runif(ncell(r))
r[1:5] <- NA
r <- r * r * r * 5
freq(r)

freq(r, value=2)

s <- stack(r, r*2, r*3)
freq(s, merge=TRUE)

Example output

Loading required package: sp
     value count
[1,]     0   288
[2,]     1   143
[3,]     2    82
[4,]     3    64
[5,]     4    42
[6,]     5    24
[7,]    NA     5
[1] 82
   value layer.1 layer.2 layer.3
1      0     288     244     221
2      1     143      83      67
3      2      82      74      53
4      3      64      58      53
5      4      42      42      37
6      5      24      28      36
7      6      NA      33      29
8      7      NA      24      17
9      8      NA      26      19
10     9      NA      18      24
11    10      NA      13      21
12    11      NA      NA      14
13    12      NA      NA      11
14    13      NA      NA      17
15    14      NA      NA      12
16    15      NA      NA      12
17    NA       5       5       5

raster documentation built on June 18, 2021, 9:08 a.m.