pick: Pick example values

Description Usage Arguments Details Value See Also Examples

View source: R/pick.R

Description

Given a characher vector, take samples from that vector, and then the unique value of those samples

Usage

1
pick(x, n, value = FALSE, w = FALSE, na.rm = TRUE)

Arguments

x

A character vector from which to pick

n

How many samples to pick

value

Logical, return value? Default FALSE returns logical index index

w

Logical, weight by the frequency occurence of each unique value? (default TRUE )

na.rm

Logical, remove NA's from consideration?

Details

The anticipated use-case related to trawl data is subsampling a data set.

Value

Either a logical vector of same length as x, or a a vector with same class as x and length n

See Also

mpick

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# =========
# = Basic Use =
# =========
# simple example
pick(letters, 5)

# more complicated
# make suitable vector to illustrate
v <- trunc(rlnorm(1E3))
ind2NA <- sample.int(n=length(v), size=length(v)/2)
v[ind2NA] <- NA_real_ # set half to NA

# repeat simple use
set.seed(42)
ind <- pick(v, 2)

# show value from simple use
v[ind]


# get simple use unique value directly
set.seed(42)
pick(v, 2, value=TRUE)


# allow sampling of NA's, and weight
set.seed(42)
pick(x=v, n=2, value=TRUE, na.rm=TRUE, w=TRUE)

# ===============
# = E.g. for Trawl Data =
# ===============
expr <- expression(
	pick(spp, 3, w=TRUE)
	& pick(year, 2)
	& keep.row
)
mini_data <- clean.ai[eval(expr)]
# When combining logical vectors with &,
# might end up with less than n;
# if you combine with |, likely to end up w/ more
# (could subset iteratively to ensure)
mini_data[,list(nSpp=lu(spp), nY=lu(year))]

rBatt/trawlData documentation built on May 26, 2019, 7:45 p.m.