Skip to content

Is there a Truth Table Generator in R?

2 messages · Jeff Newmiller, Paul Bernal

#
Please keep the list included in the thread using reply-all...

tt[,3:1] reverses the columns in tt. The expand.grid function cycles through possible values most quickly in the first column, which is useful if you intend to convert the result to a matrix, but is not conventional for truth tables.

Here is a generalized version for any sequence of legal R symbol labels nm:

both <- c( FALSE, TRUE )
nm <- letters[ 1:4 ]
tt <- rev( do.call( expand.grid, setNames( rep( list( both ), length( nm ) ), rev( nm ) ) ) )
tt

or in R 4.1+...

tt <- (  list( both )
      |> rep( length( nm ) )
      |> setNames( rev( nm ) )
      |> ( \(.) do.call( expand.grid, . ) )()
      |> rev()
      )
On March 12, 2022 9:08:23 AM PST, Paul Bernal <paulbernal07 at gmail.com> wrote:

  
    
#
Dear Jeff,

Thank you so much for your extremely valuable feedback. I apologize for not
doing the reply all, forgot it.

Best regards,
Paul

El s?b, 12 mar 2022 a las 12:47, Jeff Newmiller (<jdnewmil at dcn.davis.ca.us>)
escribi?: