Er, rbind is not merge... do.call expects the function you specify to handle
all the elements of the list in a single invocation... Reduce will work with a
two-argument function.
Reduce(merge, df.list, accumulate=TRUE, by='date')
For clarity: apply and the like have for loops inside them, so th
Short answer: do.call()
do.call("rbind", df.list)
will rbind all of the data frames in df.list.
You may have to tidy up row names afterwards, and you will need to make sure
that the data frames all have the same column names and each column has the
same class, or you'll get unexpected results.
> On 25 Jul 2018, at 08:17, Naresh Gurbuxani
> wrote:
>
> I have a list whose components are data frames. My goal is to construct a
> data frame by merging all the list components. Is it possible to achieve
> this using apply and without a for loop, as used below?
>
> Thanks,
> Naresh
>
Is this what you want:
> random <- expand.grid(R1 = 1:5, R2 = -(1:5))
> result <- cbind(F1 = 10, F2 = 100, random)
>
> result
F1 F2 R1 R2
1 10 100 1 -1
2 10 100 2 -1
3 10 100 3 -1
4 10 100 4 -1
5 10 100 5 -1
6 10 100 1 -2
7 10 100 2 -2
8 10 100 3 -2
9 10 100 4 -2
10 10 100
On Fri, Oct 15, 2010 at 6:46 AM, David A. wrote:
>
> Thanks Dennis,
>
> I don't think it was a problem of not feeding in a function for rollapply(),
> because I was using mean() and my co.var() function in the FUN argument.
> The key part seems to be the transformation that zoo() does to the matr
atrix, the rollapply() function now
works fine.
Thanks again
David
Date: Fri, 15 Oct 2010 03:00:27 -0700
Subject: Re: [R] using apply function and storing output
From: djmu...@gmail.com
To: dasol...@hotmail.com
CC: r-help@r-project.org
Hi:
You need to give a function for rollapply() to
eated function...
>
> > xxx<-rollapply(ord_raw_filt.df,3,FUN=co.var,by=3)
> Error in UseMethod("rollapply") :
> no applicable method for 'rollapply' applied to an object of class
> "c('matrix', 'integer', 'numeric')
ed function...
> xxx<-rollapply(ord_raw_filt.df,3,FUN=co.var,by=3)
Error in UseMethod("rollapply") :
no applicable method for 'rollapply' applied to an object of class
"c('matrix', 'integer', 'numeric')"
Can you help me with the error?
one efficient way to do this, avoiding loops, is using the rowsum()
function, e.g.,
mat <- matrix(rnorm(1710*244), 1710, 244)
id <- rep(seq_len(570), each = 3)
means <- rowsum(mat, id, FALSE) / 3
Regarding the second part of your question, indeed a "gold" rule of
efficient R programming when
Hi:
Look into the rollmean() function in package zoo.
HTH,
Dennis
On Fri, Oct 15, 2010 at 12:34 AM, David A. wrote:
>
> Hi list,
>
> I have a 1710x244 matrix of numerical values and I would like to calculate
> the mean of every group of three consecutive values per column to obtain a
> new mat
Thanks a lot.
All the three approaches work for me!
On Sun, Jan 31, 2010 at 10:43 PM, hadley wickham wrote:
> On Sun, Jan 31, 2010 at 5:05 PM, Sunny Srivastava
> wrote:
> > Dear R-Helpers,
> > I have a data.frame (df) and the head of data.frame looks like
> >
> > ProbeUID ControlType Pr
On Sun, Jan 31, 2010 at 5:05 PM, Sunny Srivastava
wrote:
> Dear R-Helpers,
> I have a data.frame (df) and the head of data.frame looks like
>
> ProbeUID ControlType ProbeName GeneName SystematicName
> 1665 1577 0 pSysX_50_22_1 pSysX_50 pSysX_50
> 5422 5147
On Jan 31, 2010, at 6:05 PM, Sunny Srivastava wrote:
Dear R-Helpers,
I have a data.frame (df) and the head of data.frame looks like
ProbeUID ControlType ProbeName GeneName SystematicName
1665 1577 0 pSysX_50_22_1 pSysX_50 pSysX_50
5422 5147 0 pSysX_49
13 matches
Mail list logo