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

2020-04-17 Thread Eric Berger
4 > 2 1 4 5 1 > > Results should be OK although its structure is different, performance is > not tested. > > Cheers > Petr > > > -Original Message- > > From: R-help On Behalf Of David McPearson > > Sent: Friday, April 17, 2020 7:50 AM > >

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

2020-04-16 Thread PIKAL Petr
etr > -Original Message- > From: R-help On Behalf Of David McPearson > Sent: Friday, April 17, 2020 7:50 AM > To: r-help@r-project.org > Cc: dc...@telstra.com > Subject: Re: [R] calculate row median of every three columns for a dataframe > > Anna wrote: > > > > Hi al

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

2020-04-16 Thread David McPearson
Anna wrote: Hi all, I need to calculate a row median for every three columns of a dataframe. I made it work using the following script, but not happy with the script. Is there a simpler way for doing this? To which Jim L responded: Hi Anna, I can't think of a simple way, but this fun

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

2020-04-16 Thread Bert Gunter
Inline. 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 Thu, Apr 16, 2020 at 5:28 PM Jim Lemon wrote: > Hi Anna, > I can't think of a simple way, but this fun

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

2020-04-16 Thread Jim Lemon
Hi Anna, I can't think of a simple way, but this function may make you happier: step_median<-function(x,window) { x<-unlist(x) stop<-length(x)-window+1 xout<-NA nindx<-1 for(i in seq(1,stop,by=window)) { xout[nindx]<-do.call("median",list(x[i:(i+window-1)])) nindx<-nindx+1 } return(xout

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

2020-04-16 Thread Bert Gunter
You have *not* calculated row medians for all combinations of (is that what you meant?) 3 columns of your data frame. ?combn with column indexing can help you do that. If that is not what you meant, then ?? Bert Gunter "The trouble with having an open mind is that people keep coming along and s

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

2020-04-16 Thread aiguo li via R-help
Hi all, I need to calculate a row median for every three columns of a dataframe.  I made it work using the following script, but not happy with the script.  Is there a simpler way for doing this? df = data.frame("a"=c(2,3,4), "b"=c(3,5,1),"c"=c(1,3,6),"d"=c(7,2,1),"e"=c(2,5,3),"f"=c(4,5,1))tmed