str_C.expand.grid: R Utilities: String Paste Combined with 'expand.grid'

View source: R/str_C.expand.grid.R

str_C.expand.gridR Documentation

R Utilities: String Paste Combined with expand.grid

Description

String paste combined with expand.grid

Usage

str_C.expand.grid(xlist, indices=NULL)

Arguments

xlist

A list of character vectors

indices

Optional vector of indices to be permuted in xlist

Value

A character vector

Examples

#############################################################################
# EXAMPLE 1: Some toy examples
#############################################################################

x1 <- list( c("a","b" ), c("t", "r","v") )
str_C.expand.grid( x1 )
  ##   [1] "at" "bt" "ar" "br" "av" "bv"

x1 <- list( c("a","b" ), paste0("_", 1:4 ), c("t", "r","v") )
str_C.expand.grid( x1, indices=c(2,1,3) )
  ##    [1] "_1at" "_1bt" "_2at" "_2bt" "_3at" "_3bt" "_4at" "_4bt" "_1ar" "_1br"
  ##   [11] "_2ar" "_2br" "_3ar" "_3br" "_4ar" "_4br" "_1av" "_1bv" "_2av" "_2bv"
  ##   [21] "_3av" "_3bv" "_4av" "_4bv"

## Not run: 
##***************************************************************************
## The function 'str_C.expand.grid' is currently defined as
function( xlist, indices=NULL )
{
     xeg <- expand.grid( xlist)
     if ( ! is.null(indices) ){    xeg <- xeg[, indices ]}
     apply( xeg, 1, FUN=function(vv){ paste0( vv, collapse="") } )
}
##***************************************************************************

## End(Not run)

miceadds documentation built on May 29, 2024, 11:05 a.m.