Re: [R] Finding combination of states

2023-09-07 Thread Ebert,Timothy Aaron
is something I want to keep for a long time, then it pays in the long run to use the fewest packages possible. Tim -Original Message- From: R-help On Behalf Of Richard O'Keefe Sent: Thursday, September 7, 2023 6:52 AM To: Bert Gunter Cc: r-help Subject: Re: [R] Finding combination of states

Re: [R] Finding combination of states

2023-09-07 Thread Richard O'Keefe
ient way to do this, of course. > > >> > > >> Cheers, > > >> Bert > > >> > > >> > > >> On Mon, Sep 4, 2023 at 12:57 PM Eric Berger > > wrote: > > >>> > > >>> My initial response was buggy and a

Re: [R] Finding combination of states

2023-09-05 Thread Bert Gunter
it(s, NULL)) > >>> sum(v[-1]==v[-length(v)]) == 0 > >>> } > >>> > >>> f <- function(states, nsteps, first, last, rm_repeat=TRUE) { > >>> if (nsteps < 3) stop("nsteps must be at least 3") > >>> out <-

Re: [R] Finding combination of states

2023-09-05 Thread Eric Berger
te(first, >>> myExpand(states, nsteps-2) |> >>> apply(MAR=1, \(x) paste(x, collapse="")), >>> last, sep="") >>> if (rm_repeat) { >>> ok <- sapply(out, no_repeat) >>> out &

Re: [R] Finding combination of states

2023-09-04 Thread Bert Gunter
tates, nsteps-2) |> >> apply(MAR=1, \(x) paste(x, collapse="")), >> last, sep="") >> if (rm_repeat) { >> ok <- sapply(out, no_repeat) >> out <- out[ok] >> } >> out >> } >

Re: [R] Finding combination of states

2023-09-04 Thread Bert Gunter
nit,expand.grid(rep(list(states), ntimes-2)), final)) >>> } >>> >>> e.g. >>> >>> > g(4, LETTERS[1:5], "B", "D") >>> [1] "BAAD" "BBAD" "BCAD" "BDAD" "BEAD" &q

Re: [R] Finding combination of states

2023-09-04 Thread Eric Berger
"BEBD" "BACD" "BBCD" "BCCD" "BDCD" "BECD" "BADD" >> [17] "BBDD" "BCDD" "BDDD" "BEDD" "BAED" "BBED" "BCED" "BDED" >> [25] "

Re: [R] Finding combination of states

2023-09-04 Thread Bert Gunter
nk the OP will have to clarify his query. > > Cheers, > Bert > > On Mon, Sep 4, 2023 at 9:25 AM Ebert,Timothy Aaron wrote: > >> Does this work for you? >> >> t0<-t1<-t2<-LETTERS[1:5] >> al2<-expand.grid(t0, t1, t2) >> al3<-paste(al2$Var1,

Re: [R] Finding combination of states

2023-09-04 Thread Bert Gunter
On Mon, Sep 4, 2023 at 9:25 AM Ebert,Timothy Aaron wrote: > Does this work for you? > > t0<-t1<-t2<-LETTERS[1:5] > al2<-expand.grid(t0, t1, t2) > al3<-paste(al2$Var1, al2$Var2, al2$Var3) > al4 <- gsub(" ", "", al3) > head(al3) > > T

Re: [R] Finding combination of states

2023-09-04 Thread Ebert,Timothy Aaron
10:17 AM To: Christofer Bogaso Cc: r-help Subject: Re: [R] Finding combination of states [External Email] The function purrr::cross() can help you with this. For example: f <- function(states, nsteps, first, last) { paste(first, unlist(lapply(purrr::cross(rep(list(v),nsteps-2)), \(x) p

Re: [R] Finding combination of states

2023-09-04 Thread Eric Berger
The function purrr::cross() can help you with this. For example: f <- function(states, nsteps, first, last) { paste(first, unlist(lapply(purrr::cross(rep(list(v),nsteps-2)), \(x) paste(unlist(x), collapse=""))), last, sep="") } f(LETTERS[1:5], 3, "B", "E") [1] "BAE" "BBE" "BCE" "BDE" "BEE"

[R] Finding combination of states

2023-09-04 Thread Christofer Bogaso
Let say I have 3 time points.as T0, T1, and T2.(number of such time points can be arbitrary) In each time point, an object can be any of 5 states, A, B, C, D, E (number of such states can be arbitrary) I need to find all possible ways, how that object starting with state B (say) at time T0, can