Re: [R] R grep question

2021-05-26 Thread Jeff Newmiller
Post in plain text Use grepl On May 26, 2021 9:29:10 PM PDT, Kai Yang via R-help wrote: >Hi List, >I wrote the code to create a new variable: >CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No") >  > >I need to create MMR.gene column in CRC data frame, ifgene.all column >c

Re: [R] Testing optimization solvers with equality constraints

2021-05-26 Thread Abby Spurdle
I meant: x0 = c (1, 1e-3, 0) Not: x0 = c (1, 1e6, 0) So, large intentional error may work too. Possibly, better...? On Thu, May 27, 2021 at 6:00 PM Abby Spurdle wrote: > > If I can re-answer the original post: > There's a relatively simple solution. > (For these problems, at least). > > #wrong

Re: [R] Testing optimization solvers with equality constraints

2021-05-26 Thread Abby Spurdle
If I can re-answer the original post: There's a relatively simple solution. (For these problems, at least). #wrong x0 = c (1, 0, 0) NlcOptim::solnl(x0, objfun = f, confun = conf)$par Rdonlp2::donlp2(x0, fn = f, nlin = list(heq), nlin.lower = 0, nlin.upper = 0)$par #right x0 = c (1, 1e6, 0) NlcOpt

[R] R grep question

2021-05-26 Thread Kai Yang via R-help
Hi List, I wrote the code to create a new variable: CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No")   I need to create MMR.gene column in CRC data frame, ifgene.all column contenes MLH1 or MSH2, then the MMR.gene=Yes, if not,MMR.gene=No But, the code doesn't work for me

Re: [R] Testing optimization solvers with equality constraints

2021-05-26 Thread Abby Spurdle
I need to retract my previous post. (Except the part that the R has extremely good numerical capabilities). I ran some of the examples, and Hans W was correct. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mai

Re: [R] Decompose df1 into another df2 based on values in df1

2021-05-26 Thread Bert Gunter
Thank you for the reprex. However your specification was too vague for me to know exactly what your data are like, so I tried to assume the most general possibility, with the consequence that I may be giving you an answer to the wrong question. Hopefully, you can adjust as needed to get what you wa

[R] Decompose df1 into another df2 based on values in df1

2021-05-26 Thread Adrian Johnson
Hello, I am trying to convert a df (given below as d1) into df2 (given below as res). I tried using loops for each row. I cannot get it right. Moreover the df is 25 x 500 in dimension and I cannot get it to work. Could anyone help me here please. Thanks. Adrian. d1 <- structure(list(S1 =

Re: [R] [External Email] Group by and add a constant value based on a condition dply

2021-05-26 Thread Rui Barradas
Hello, I too don't see why grouping is needed but here it goes. df1 %>% group_by(Department, Class) %>% mutate(Value = Value + 5*(Date == "4.01.2020")) Hope this helps, Rui Barradas Às 17:01 de 26/05/21, Christopher W Ryan via R-help escreveu: Is the grouping beforehand necessary? Coul

Re: [R] [External Email] Group by and add a constant value based on a condition dply

2021-05-26 Thread Christopher W Ryan via R-help
Is the grouping beforehand necessary? Could you simply, "for all the dates that are "4.01.2020" and have the "Value" greater than zero add 5 to the "Value" "? I may be missing something. --Chris Ryan On Wed, May 26, 2021 at 11:53 AM Elahe chalabi via R-help < r-help@r-project.org> wrote: > Hi

[R] Group by and add a constant value based on a condition dply

2021-05-26 Thread Elahe chalabi via R-help
Hi everyone, I have the following dataframe:        structure(list(Department = c("A", "A", "A", "A", "A", "A", "A",       "A", "B", "B", "B", "B", "B", "B", "B", "B"), Class = c(1L, 1L,      1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), Value = c(0L,      100L, 800L, 800L, 0L, 300L,