every_nth: Select every n'th element

Description Usage Arguments Examples

View source: R/every_nth.R

Description

Select every second, third, fourth etc. element (or slice/hyperplane) of an object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
every_nth(...)

## Default S3 method:
every_nth(x, n = 2, start = 1, ...)

## S3 method for class 'matrix'
every_nth(x, n = 2, start = 1, margin = 1, ...)

## S3 method for class 'array'
every_nth(x, n = 2, start = 1, margin = 1, ...)

## S3 method for class 'data.frame'
every_nth(x, n = 2, start = 1, margin = 1, ...)

## S3 method for class 'list'
every_nth(x, n = 2, start = 1, ...)

Arguments

...

further arguments passed to methods

x

an object to be selected from

n

selection "step size"

start

integer in [1:n] specifying the start of selection

margin

what margin to select along

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
m <- matrix(1:64, 8)
every_nth(m, n=3, start=3, margin=2)

d <- data.frame(A=1:8, B=2:9, Q=letters[rep(1:3, length.out=8)])
every_nth(d, start=2)

a <- array(1:6^4, rep(6, 4))
every_nth(a)

l <- list(a=1:3, b=2:6, c=8:5, d=9:7, e=list(ea=1:2, eb=1), f=2:6)
every_nth(l, n=2, start=2)

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.