Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Subset

Subset a Data Array


Description

This function allows to subset (i.e. slice, take a chunk of) an array, in a similar way as done in the function take() in the package plyr. There are two main inprovements:

The input array can have dimension names, either in names(dim(x)) or in the attribute 'dimensions', and the dimensions to subset along can be specified via the parameter along either with integer indices or either by their name.

There are additional ways to adjust which dimensions are dropped in the resulting array: either to drop all, to drop none, to drop only the ones that have been sliced or to drop only the ones that have not been sliced.

If an array is provided without dimension names, dimension names taken from the parameter dim_names will be added to the array.

Usage

Subset(x, along, indices, drop = FALSE)

Arguments

x

A multidimensional array to be sliced. It can have dimension names either in names(dim(x)) or either in the attribute 'dimensions'.

along

Vector with references to the dimensions to take the subset from: either integers or dimension names.

indices

List of indices to take from each dimension specified in 'along'. If a single dimension is specified in 'along' the indices can be directly provided as a single integer or as a vector.

drop

Whether to drop all the dimensions of length 1 in the resulting array, none, only those that are specified in 'along', or only those that are not specified in 'along'. The possible values are, respectively: 'all' or TRUE, 'none' or FALSE, 'selected', and 'non-selected'.

Examples

subset <- Subset(sampleMap$mod, c('dataset', 'sdate', 'ftime'), 
                list(1, 1, 1), drop = 'selected')
PlotLayout(PlotEquiMap, c('lat', 'lon'), subset, 
          sampleMap$lon, sampleMap$lat, 
          titles = paste('Member', 1:3))

s2dverification

Set of Common Tools for Forecast Verification

v2.10.0
Apache License 2.0
Authors
BSC-CNS [aut, cph], Virginie Guemas [aut], Nicolau Manubens [aut], An-Chi Ho [ctb, cre], Nuria Perez-Zanon [ctb], Javier Garcia-Serrano [aut], Neven Fuckar [aut], Louis-Philippe Caron [aut], Omar Bellprat [aut], Luis Rodrigues [aut], Veronica Torralba [aut], Alasdair Hunter [aut], Chloe Prodhomme [aut], Martin Menegoz [aut], Domingo Manubens [ctb], Constantin Ardilouze [ctb], Lauriane Batte [ctb], Fabian Lienert [ctb], Julia Giner [ctb], Jean-Philippe Baudouin [ctb], Nube Gonzalez [ctb], Ludovic Auger [ctb], Nicola Cortesi [ctb], Eleftheria Exarchou [ctb], Ruben Cruz [ctb], Isabel Andreu-Burillo [ctb], Ramiro Saurral [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.