Re: [R] custom function gives unexpected result - for me

2020-04-17 Thread Monica Palaseanu-Lovejoy
Hi, I cannot believe I did that. Usually I remember to add parenthesis but this time obviously I didn’t. Thank you all so much for answering so quickly. Thanks, Monica On Fri, Apr 17, 2020 at 7:06 PM Peter Langfelder wrote: > You need 1:(m-1) in your function. The operator : has precedence ove

Re: [R] [FORGED] custom function gives unexpected result - for me

2020-04-17 Thread Jeff Newmiller
A different solution: grr2 <- function( rn ) { f <- function( i ) { if ( 0 == i %% 2 ) seq.int( i ) else seq( i, 1 ) } L <- lapply( seq.int( rn - 1 ), f ) do.call( c, L ) } On April 17, 2020 5:11:40 PM PDT, Jeff Newmiller wrote: >A useful help page: > >?Syntax > >On April 17, 20

Re: [R] [FORGED] custom function gives unexpected result - for me

2020-04-17 Thread Jeff Newmiller
A useful help page: ?Syntax On April 17, 2020 4:26:19 PM PDT, Rolf Turner wrote: > > >The answer is very simple: parentheses. (Also think about "operator >precedence".) If you assign rn <- 3, then 1:rn-1 is: > >[1] 0 1 2 > >The "-" operator is applied *after* the ":" operator. > >You want 1:

Re: [R] [FORGED] custom function gives unexpected result - for me

2020-04-17 Thread Rolf Turner
The answer is very simple: parentheses. (Also think about "operator precedence".) If you assign rn <- 3, then 1:rn-1 is: [1] 0 1 2 The "-" operator is applied *after* the ":" operator. You want 1:(rn-1) which gives [1] 1 2 and the desired result. cheers, Rolf Turner On 18/04/20 7:5

Re: [R] Multi response GAM

2020-04-17 Thread Bert Gunter
https://cran.r-project.org/web/views/Multivariate.html https://cran.r-project.org/web/views/Environmetrics.html https://cran.r-project.org/web/views/TimeSeries.html Also search on "multiresponse GAM" or similar at rseek.org. This brought up what looked to me like useful hits. And of course, don't

Re: [R] Multi response GAM

2020-04-17 Thread Abby Spurdle
It might be possible via the VGAM package: https://cran.r-project.org/package=VGAM But I've never used this package, so not sure. It may also be possible to use a single response, by including additional explanatory terms. This is what I would do, if I could... Noting that some GAM implementatio

Re: [R] custom function gives unexpected result - for me

2020-04-17 Thread Peter Langfelder
You need 1:(m-1) in your function. The operator : has precedence over -: > 1:3-1 [1] 0 1 2 > 1:(3-1) [1] 1 2 Happened to me a few times as well before I remembered. HTH, Peter On Fri, Apr 17, 2020 at 3:50 PM Monica Palaseanu-Lovejoy wrote: > > Hi, > > I wrote a relatively simple function. If

[R] Multi response GAM

2020-04-17 Thread Tristan Kosciuch
Hello, I am modelling the diet of Nile perch through time. I have 3 diet classes as my response variables; fish 1, fish 2, and invertebrates. The response variables are correlated, declines in invert consumption ~ increase in fish consumption. Any advice on how to handle this would be appreciated

[R] custom function gives unexpected result - for me

2020-04-17 Thread Monica Palaseanu-Lovejoy
Hi, I wrote a relatively simple function. If i run the code inside the function line by line i am getting the result i was expecting, but if i run the function, i get a different result. The function: grr1 <- function(rn) { r.up <- c() for (i in 1:rn-1) { if (i%%2==0) ru <- seq(1,i) else ru <- s

Re: [R] Survival analysis

2020-04-17 Thread Medic
On 2020-04-17 20:06, Medic wrote: > I can't understand how to do a survival analysis (?Surv ()) when some > event occurred before the start of observation (left censored). If I > understand correctly, there are two methods. I chose a method with: 1) > time from the start of treatment to the event a

Re: [R] Survival analysis

2020-04-17 Thread cpolwart
On 2020-04-17 20:06, Medic wrote: I can't understand how to do a survival analysis (?Surv ()) when some event occurred before the start of observation (left censored). If I understand correctly, there are two methods. I chose a method with: 1) time from the start of treatment to the event and 2)

[R] Survival analysis

2020-04-17 Thread Medic
I can't understand how to do a survival analysis (?Surv ()) when some event occurred before the start of observation (left censored). If I understand correctly, there are two methods. I chose a method with: 1) time from the start of treatment to the event and 2) the indicator of the event. I did (i

Re: [R] calculate row median of every three columns for a dataframe

2020-04-17 Thread Eric Berger
Some comments on the contributions: a) for Petr's suggestion, to return the desired structure modify the statement to t(aggregate(t(dfr), list(idx), median)[,-1]) And, although less readable, can certainly be put in a one-liner solution by removing the idx definition t(aggregate(

Re: [R] parsing DOB data

2020-04-17 Thread Jim Lemon
Hi Peter, I worked out a neat function to add the century to short dates. It works fine on its own, but sadly it bombs when used with sapply. Maybe someone else can point out my mistake: add_century<-function(x,changeover=68,previous=19,current=20,pos=1,sep="-") { xsplit<-unlist(strsplit(x,sep))