Description Usage Arguments Details Value See Also Examples

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

1 |

`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? |

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

Either a logical vector of same length as `x`

, or a a vector with same class as `x`

and length `n`

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))]
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.