Learn R Programming

irtQ (version 1.0.0)

bind.fill: Bind Fill

Description

This function creates a matrix using either row-wise (rbind) or column-wise (cbind) binding of a list of numeric vectors with varying lengths. Shorter vectors are padded with a specified fill value.

Usage

bind.fill(List, type = c("rbind", "cbind"), fill = NA)

Value

A matrix formed by binding the elements of the list either row-wise or column-wise, with shorter vectors padded by the specified fill value.

Arguments

List

A list containing numeric vectors of possibly different lengths.

type

A character string indicating the type of binding to perform. Options are "rbind" or "cbind".

fill

A value used to fill missing elements when aligning the vectors. For type = "cbind", this fills missing rows in shorter columns; for type = "rbind", this fills missing columns in shorter rows. Accepts any R object (e.g., numeric, character, logical). Default is NA.

Author

Hwanggyu Lim hglim83@gmail.com

Examples

Run this code
# Sample list
score_list <- list(item1 = 0:3, item2 = 0:2, item3 = 0:5, item4 = 0:4)

# 1) Create a row-bound matrix (rbind)
bind.fill(score_list, type = "rbind")

# 2) Create a column-bound matrix (cbind)
bind.fill(score_list, type = "cbind")

# 3) Create a column-bound matrix and fill missing values with 0
bind.fill(score_list, type = "cbind", fill = 0L)

Run the code above in your browser using DataLab