[R] Is there a Truth Table Generator in R?
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Sat Mar 12 18:47:33 CET 2022
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 ) ) ) )
or in R 4.1+...
tt <- ( list( both )
|> rep( length( nm ) )
|> setNames( rev( nm ) )
|> ( \(.) do.call( expand.grid, . ) )()
On March 12, 2022 9:08:23 AM PST, Paul Bernal <paulbernal07 using gmail.com> wrote:
>Thank you so much for your valuable feedback. at the end, in the command tt
><- [,3:1] what exactly does this do? If I wanted to create code to
>accomodate for any number of variables, how would I change that code?
>El sáb, 12 mar 2022 a las 12:04, Jeff Newmiller (<jdnewmil using dcn.davis.ca.us>)
>> both <- c( FALSE, TRUE )
>> tt <- expand.grid( C = both
>> , B = both
>> , A = both
>> tt <- tt[, 3:1 ]
>> On March 12, 2022 8:42:28 AM PST, Paul Bernal <paulbernal07 using gmail.com>
>> >Dear friends,
>> >Hope you are doing great. I have been searching for a truth table
>> >in R, but everything I find has a Python implementation instead.
>> >Maybe there is in fact a truth table generator in R, but I am not
>> >in the right places?
>> >Any help and/or guidance will be greatly appreciated.
>> >Best regards,
>> > [[alternative HTML version deleted]]
>> >R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >PLEASE do read the posting guide
>> >and provide commented, minimal, self-contained, reproducible code.
>> Sent from my phone. Please excuse my brevity.
Sent from my phone. Please excuse my brevity.
More information about the R-help