[R] Is there a Truth Table Generator in R?
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Sat Mar 12 19:33:38 CET 2022
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) ## or
Var1 Var2 Result
1 TRUE TRUE TRUE
2 FALSE TRUE TRUE
3 TRUE FALSE TRUE
4 FALSE FALSE FALSE
> tt(dat, all) ## and
Var1 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-then
Var1 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 using 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 using 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 using 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 using 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.
More information about the R-help
mailing list