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 at gmail.com> wrote:>Dear friends, > >Hope you are doing great. I have been searching for a truth table generator >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 searching >in the right places? > >Any help and/or guidance will be greatly appreciated. > >Best regards, >Paul > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- Sent from my phone. Please excuse my brevity.
As Tim pointed out, your query is rather vague. A reprex would have really helped here: please include them whenever possible in future queries. As Spencer said, a simple search would likely have yielded whatever you were seeking. Do make such efforts before posting. And as Jeff indicated, it's most likely straightforward to create a function that does what you want de novo. Here is such a function based on my guess of what you meant: tt <- function(tabl, fun) {## fun is a function that when applied rowwise to ## the logical data frame tabl yields a ## logical result cbind(tabl, Result = apply(tabl,1,fun)) } ## some examples> tt(dat,any) ## orVar1 Var2 Result 1 TRUE TRUE TRUE 2 FALSE TRUE TRUE 3 TRUE FALSE TRUE 4 FALSE FALSE FALSE> tt(dat, all) ## andVar1 Var2 Result 1 TRUE TRUE TRUE 2 FALSE TRUE FALSE 3 TRUE FALSE FALSE 4 FALSE FALSE FALSE> tt(dat, function(x) !x[1] | x[2]) ## if-thenVar1 Var2 Result 1 TRUE TRUE TRUE 2 FALSE TRUE TRUE 3 TRUE FALSE FALSE 4 FALSE FALSE TRUE Cheers, Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Mar 12, 2022 at 9:13 AM Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> > 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 at gmail.com> wrote: > >Dear friends, > > > >Hope you are doing great. I have been searching for a truth table generator > >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 searching > >in the right places? > > > >Any help and/or guidance will be greatly appreciated. > > > >Best regards, > >Paul > > > > [[alternative HTML version deleted]] > > > >______________________________________________ > >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >https://stat.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > >and provide commented, minimal, self-contained, reproducible code. > > -- > Sent from my phone. Please excuse my brevity. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
To the end of Jeff's program add tt$truth <- tt$A & tt$B & tt$C to evaluate the outcome of expand.grid. Tim -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Jeff Newmiller Sent: Saturday, March 12, 2022 12:05 PM To: r-help at r-project.org; Paul Bernal <paulbernal07 at gmail.com>; R <r-help at r-project.org> Subject: Re: [R] Is there a Truth Table Generator in R? [External Email] 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 at gmail.com> wrote:>Dear friends, > >Hope you are doing great. I have been searching for a truth table >generator 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 >searching in the right places? > >Any help and/or guidance will be greatly appreciated. > >Best regards, >Paul > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailm >an_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRz >sn7AkP-g&m=Cj0cRxlu_GS0ARzvxm-eD27PhuhkgT_azaq1hamiYDmCglHF8_9hGTAkcDNo >ZtUq&s=h0wdH7OvIxKWgjwFmBIGHvswAKy8VKwyyI3IbB9dKkc&e>PLEASE do read the posting guide >https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org >_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsR >zsn7AkP-g&m=Cj0cRxlu_GS0ARzvxm-eD27PhuhkgT_azaq1hamiYDmCglHF8_9hGTAkcDN >oZtUq&s=tsrpB1zmIQL_wMcn70xPEkvpaisBrAM9k2OQ8kDrebw&e>and provide commented, minimal, self-contained, reproducible code.-- Sent from my phone. Please excuse my brevity. ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=Cj0cRxlu_GS0ARzvxm-eD27PhuhkgT_azaq1hamiYDmCglHF8_9hGTAkcDNoZtUq&s=h0wdH7OvIxKWgjwFmBIGHvswAKy8VKwyyI3IbB9dKkc&ePLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=Cj0cRxlu_GS0ARzvxm-eD27PhuhkgT_azaq1hamiYDmCglHF8_9hGTAkcDNoZtUq&s=tsrpB1zmIQL_wMcn70xPEkvpaisBrAM9k2OQ8kDrebw&eand provide commented, minimal, self-contained, reproducible code.