expand.grid1 {lazy.tools}R Documentation

expand.grid with rev and colnames option

Description

expand.grid with rev and colnames option

Usage

expand.grid1(
  ...,
  rev = 1,
  colnames = 0,
  KEEP.OUT.ATTRS = TRUE,
  stringsAsFactors = FALSE
)

Arguments

...

vectors, factors or a list containing these.

rev

= 1 to make the last elements of ... chage first.

colnames

= 1 to use ... as the column names.

KEEP.OUT.ATTRS

a logical indicating the "out.attrs" attribute (see below) should be computed and returned.

stringsAsFactors

logical specifying if character vectors are converted to factors.

Details

See comments of native expand.grid.
Compare expand.grid( 1:2, 2:3 ) and expand.grid1( 1:2, 2:3 ).
expand.grid1( 1:2, 2:3, rev=0 ) should be equal to native expand.grid( 1:2, 2:3 ).

When the first element of ... is a list, expand.grid1 works as if it is called only with the first element. See the example below.


When ... contains a matrix, better use cprod.

Value

A data frame.

Examples


Print( expand.grid( 1:2, 2:3 ), expand.grid1( 1:2, 2:3 ) )

res=expand.grid( 1:2, c("a","b") )
res1=expand.grid1( 1:2, c("a","b") )
Print(res,res1)


ll=list(aaa=c("a","b"),bbb=1:3)
expand.grid1(ll, colnames=0)
expand.grid1(ll, colnames=1)
expand.grid1(ll, colnames=0, rev=0)
expand.grid1(ll, colnames=1, rev=0)

expand.grid(ll,ll)
expand.grid1(ll,ll)


x=c("a","b"); y=1:3
expand.grid1(x,y, colnames=0)
expand.grid1(x,y, colnames=1)
expand.grid1(x,y, colnames=0, rev=0)
expand.grid1(x,y, colnames=1, rev=0)




[Package lazy.tools version 0.1.4 ]