@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)))
Since integrate requires a function which accepts
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)
Y[[2]]-function(u) sin(u
]
*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] Vectors out of lists?
Thanks, guys... but it seems these suggestions won't work.
Let me try to be more specific with a simple
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 not a homework/puzzle type problem where you are not
allowed to use
On Wed, Nov 17, 2010 at 9:42 AM, William Dunlap wdun...@tibco.com 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
Eduardo:
On Wed, Nov 17, 2010 at 9:53 AM, Eduardo de Oliveira Horta
eduardo.oliveiraho...@gmail.com 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
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)))
Since integrate
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]]
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 number).
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
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
[1]
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]](u))
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
Thank you very much! Works like a charm!
On Tue, Nov 16, 2010 at 10:24 PM, Phil Spector spec...@stat.berkeley.eduwrote:
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 =
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[[2]]-function(u) sin(u)
Y[[3]]-function(u) 1/2*u
Ybar
15 matches
Mail list logo