> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Phil Spector
> Sent: Wednesday, 17 November 2010 10:24 AM
> To: Eduardo de Oliveira Horta
> Cc: r-help@r-project.org
> Subject: Re: [R] Vectors out of list
Eduardo:
On Wed, Nov 17, 2010 at 9:53 AM, Eduardo de Oliveira Horta
wrote:
> Thanks.
>
> I wanted to avoid loops (even inside functions) because I thought they were
> much slower than vector operations, and I really need an efficient code (not
> an exercise!).
This is a common miconception. What
On Wed, Nov 17, 2010 at 9:42 AM, William Dunlap wrote:
> Don't fixate on avoiding loops. Bury them in a function
> so you don't have to see them and then you just want something
> that does the right thing quickly enough. (I'm assuming
> this is not a homework/puzzle type problem where you are
help@r-project.org
> Subject: Re: [R] Vectors out of lists?
>
> Don't fixate on avoiding loops. Bury them in a function
> so you don't have to see them and then you just want something
> that does the right thing quickly enough. (I'm assuming
> this is n
t; --
> *From:* Eduardo de Oliveira Horta [mailto:eduardo.oliveiraho...@gmail.com]
>
> *Sent:* Tuesday, November 16, 2010 4:15 PM
> *To:* David Winsemius
> *Cc:* Phil Spector; r-help@r-project.org; www...@gmail.com; William Dunlap
>
> *Subject:* Re: [R] V
mail.com;
William Dunlap
Subject: Re: [R] Vectors out of lists?
Thanks, guys... but it seems these suggestions won't work.
Let me try to be more specific with a simple example:
Y<-list()
Y[[1]]<-function(u) sqrt(u
Eduardo de Oliveira Horta
Cc: r-help@r-project.org
Subject: Re: [R] Vectors out of lists?
Eduardo -
Thanks for the reproducible example!
Y<-list()
Y[[1]]<-function(u) sqrt(u)
Y[[2]]<-function(u) sin(u)
Y[[3]]<-function(u) 1/2*u
Ybar = function(u)mean(sapply(Y,function(fun)fun(u
boun...@r-project.org] On
Behalf Of Phil Spector
Sent: Wednesday, 17 November 2010 10:24 AM
To: Eduardo de Oliveira Horta
Cc: r-help@r-project.org
Subject: Re: [R] Vectors out of lists?
Eduardo -
Thanks for the reproducible example!
> Y<-list()
> Y[[1]]<-function(u) sqrt(u)
> Y[
Thank you very much! Works like a charm!
On Tue, Nov 16, 2010 at 10:24 PM, Phil Spector wrote:
> Eduardo -
> Thanks for the reproducible example!
>
>> Y<-list()
>> Y[[1]]<-function(u) sqrt(u)
>> Y[[2]]<-function(u) sin(u)
>> Y[[3]]<-function(u) 1/2*u
>> Ybar = function(u)mean(sapply(Y,function(
Eduardo -
Thanks for the reproducible example!
Y<-list()
Y[[1]]<-function(u) sqrt(u)
Y[[2]]<-function(u) sin(u)
Y[[3]]<-function(u) 1/2*u
Ybar = function(u)mean(sapply(Y,function(fun)fun(u)))
Since integrate requires a function which accepts a vector
and returns a vector, we'd need to use Ve
Thanks, guys... but it seems these suggestions won't work.
Let me try to be more specific with a simple example:
Y<-list()
Y[[1]]<-function(u) sqrt(u)
Y[[2]]<-function(u) sin(u)
Y[[3]]<-function(u) 1/2*u
I wanted something equivalent to
Ybar<-function(u){
1/3*(Y[[1]](u) + Y[[2]](u) + Y[[3]](
On Nov 16, 2010, at 6:18 PM, Phil Spector wrote:
Eduardo -
I'd guess that
Ybar = function(u)mean(sapply(Y,function(fun)fun(u)))
I had an example to which this was offered and all it did was make
Ybar a function;
# Polymorphic Fn-object Version 1
Fs <- list(mode="language")
> Fs
$mode
[
Eduardo -
I'd guess that
Ybar = function(u)mean(sapply(Y,function(fun)fun(u)))
will do what you want, but without a reproducible example,
it's hard to tell.
- Phil Spector
Statistical Computing Facility
Try this:
u <- 1:10
mean(sapply(Y, function(f)match.fun(f)(u)))
On Tue, Nov 16, 2010 at 9:00 PM, Eduardo de Oliveira Horta <
eduardo.oliveiraho...@gmail.com> wrote:
> Hello there
>
> I have a list, Y, and each component of that list is a real-valued function
> (that is, Y[[i]](u) returns a numbe
Hello there
I have a list, Y, and each component of that list is a real-valued function
(that is, Y[[i]](u) returns a number).
I was wishing to build the mean function and the first thing I thought of
was
Ybar<-function(u){
mean(Y[[1:n]](u))
}
but obviously this doesn't work, since Y[[1:n]]
15 matches
Mail list logo