Re: [R] Vectors out of lists?

2010-11-17 Thread Phil Spector
@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

Re: [R] Vectors out of lists?

2010-11-17 Thread 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) Y[[2]]-function(u) sin(u

Re: [R] Vectors out of lists?

2010-11-17 Thread Eduardo de Oliveira Horta
] *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

Re: [R] Vectors out of lists?

2010-11-17 Thread William Dunlap
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

Re: [R] Vectors out of lists?

2010-11-17 Thread Joshua Wiley
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

Re: [R] Vectors out of lists?

2010-11-17 Thread Bert Gunter
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

Re: [R] Vectors out of lists?

2010-11-17 Thread Bill.Venables
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

[R] Vectors out of lists?

2010-11-16 Thread Eduardo de Oliveira Horta
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]]

Re: [R] Vectors out of lists?

2010-11-16 Thread Henrique Dallazuanna
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).

Re: [R] Vectors out of lists?

2010-11-16 Thread Phil Spector
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

Re: [R] Vectors out of lists?

2010-11-16 Thread David Winsemius
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]

Re: [R] Vectors out of lists?

2010-11-16 Thread Eduardo de Oliveira Horta
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))

Re: [R] Vectors out of lists?

2010-11-16 Thread Phil Spector
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

Re: [R] Vectors out of lists?

2010-11-16 Thread Eduardo de Oliveira Horta
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 =

Re: [R] Vectors out of lists?

2010-11-16 Thread Bill.Venables
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