Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Bert Gunter
Thanks, Dénes. Good points. Bert On Mon, Jul 29, 2019 at 4:33 PM Dénes Tóth wrote: > > Hi Bert, > > see inline. > > On 7/30/19 1:12 AM, Bert Gunter wrote: > > While Eric's solution is correct( mod "corner" cases like all NA's in > > a row), it can be made considerably more efficient. > > > >

Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Dénes Tóth
Hi Bert, see inline. On 7/30/19 1:12 AM, Bert Gunter wrote: While Eric's solution is correct( mod "corner" cases like all NA's in a row), it can be made considerably more efficient. One minor improvement can be made by using the idiom any(x == "A") instead of matching via %in% for the simple

Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Bert Gunter
While Eric's solution is correct( mod "corner" cases like all NA's in a row), it can be made considerably more efficient. One minor improvement can be made by using the idiom any(x == "A") instead of matching via %in% for the simple case of matching just a single value. However, a considerable

Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Eric Berger
Read the help for apply and %in% ?apply ?%in% Sent from my iPhone > On 29 Jul 2019, at 22:23, Ana Marija wrote: > > Thank you so much! Just to confirm here MARGIN=1 indicates that "A" should > appear at least once per row? > >> On Mon, Jul 29, 2019 at 1:53 PM Eric Berger wrote: >> df$case

Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Ana Marija
Thank you so much! Just to confirm here MARGIN=1 indicates that "A" should appear at least once per row? On Mon, Jul 29, 2019 at 1:53 PM Eric Berger wrote: > df$case <- apply(df,MARGIN = 1,function(v) { as.integer("A" %in% v) }) > > > On Mon, Jul 29, 2019 at 9:02 PM Ana Marija > wrote: > >>

Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Eric Berger
df$case <- apply(df,MARGIN = 1,function(v) { as.integer("A" %in% v) }) On Mon, Jul 29, 2019 at 9:02 PM Ana Marija wrote: > sorry my bad, here is the edited version: > > so the data frame is this: > > df=data.frame( > eye_problemsdisorders_f6148_0_1=c("A","C","D",NA,"D","A","C",NA,"B","A"), >

Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Ana Marija
sorry my bad, here is the edited version: so the data frame is this: df=data.frame( eye_problemsdisorders_f6148_0_1=c("A","C","D",NA,"D","A","C",NA,"B","A"), eye_problemsdisorders_f6148_0_2=c("B","C",NA,"A","C","B",NA,NA,"A","D"),

Re: [R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Eric Berger
You may have a typo/misstatement in your question. You define a data frame with 5 columns, each of which has 10 elements, so your data frame has dimensions 10 x 5. Then you request a new COLUMN which will have only 5 elements, which is not allowed. All columns of a data frame must have the same

[R] How to create a new column based on the values from multiple columns which are matching a particular string?

2019-07-29 Thread Ana Marija
I have data frame which looks like this: df=data.frame( eye_problemsdisorders_f6148_0_1=c(A,C,D,NA,D,A,C,NA,B,A), eye_problemsdisorders_f6148_0_2=c(B,C,NA,A,C,B,NA,NA,A,D), eye_problemsdisorders_f6148_0_3=c(C,A,D,D,B,A,NA,NA,A,B), eye_problemsdisorders_f6148_0_4=c(D,D,NA,B,A,C,NA,C,A,B),

Re: [R] CoxPH multivariate frailty model with coxph (survival)

2019-07-29 Thread Andrews, Chris
e short simulation I tried (except when the effect was very strong and I got convergence warnings). Chris library("flexsurv") set.seed(20190729) # Multiple non-competing outcomes, connected only by frailty (unmeasured covariate) nn <- 1000 kk <- 2 # frailty, 1 per individ

Re: [R] Monte carlo Simulation

2019-07-29 Thread Jim Lemon
Hi Tolulope, Get the Monte Carlo package: https://cran.r-project.org/web/packages/MonteCarlo/vignettes/MonteCarlo-Vignette.html and look at an online tutorial: https://www.youtube.com/watch?v=T_igE6bb6hU Jim On Mon, Jul 29, 2019 at 5:29 PM Tolulope Adeagbo wrote: > > Hello Everyone, > >

Re: [R] Monte carlo Simulation

2019-07-29 Thread Rui Barradas
Hello, Inline. Às 08:28 de 29/07/19, Tolulope Adeagbo escreveu: Hello Everyone, Please can anyone educate me on monte carlo simulation in R. Actually, no, we cannot. R-Help is for R code issues, not to teach statistics. I must have a *specific* R code problem to ask. I suggest you first

[R] Monte carlo Simulation

2019-07-29 Thread Tolulope Adeagbo
Hello Everyone, Please can anyone educate me on monte carlo simulation in R. Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help