Learn R Programming

long2lstmarray (version 0.2.0)

slice_var_sequence: Generate a matrix with various lags from a sequence

Description

Generate a matrix with various lags from a sequence

Usage

slice_var_sequence(sequence, lags, label_length = 1, label_output = TRUE)

Value

If label_output is FALSE, a matrix with the sliced sequences is returned. If label_output is TRUE, a list with the matrix and vector with the labels is returned.

Arguments

sequence

A vector representing the sequence to be sliced into many rows.

lags

The length of each sliced sequence.

label_length

How many values after are considered to be the label? Default to 1. If label_length = 1, the label value is always the value following the sliced sequence.

label_output

logical. if TRUE a list including the matrix with the sliced sequences and a vector with the labels is returned.

Examples

Run this code
slice_var_sequence(sequence = 1:30,
 lags = 3, label_length = 1,
 label_output = TRUE)
 
slice_var_sequence(sequence = 1:30, 
lags = 3, label_length = 1,
 label_output = FALSE)
 
slice_var_sequence(sequence = 1:30,
 lags = 3, label_length = 2,
  label_output = FALSE)

Run the code above in your browser using DataLab