Re: [R] Execute a function

2012-07-20 Thread Jessica Streicher
You mean executing the function for all combinations of values?
For example, if you have a-b-c-1:2
you would get back the values of

myfunc(1,1,1)
myfunc(1,1,2)
myfunc(1,2,1)
myfunc(1,2,2)
myfunc(2,1,1)
myfunc(2,1,2)
myfunc(2,2,1)
myfunc(2,2,2)

?

On 20.07.2012, at 13:05, carla moreira wrote:

 
 Hi,
 
 I would like to evaluate a function, with 3 arguments, for instance, 
 
 myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
}
 
 How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z are
 vectors?
 
 Thank you very much in advance
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Execute a function

2012-07-20 Thread Benno Pütz
Not quite sure what you are aiming at, but looking at ?mapply or ?expand.grid 
could be helpful

Benno

On Jul 20, 2012, at 1:05 PM, carla moreira wrote:

 
 Hi,
 
 I would like to evaluate a function, with 3 arguments, for instance, 
 
 myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
}
 
 How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z are
 vectors?
 
 Thank you very much in advance
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

Benno Pütz
Statistical Genetics
MPI of Psychiatry
Kraepelinstr. 2-10
80804 Munich, Germany
T: ++49-(0)89-306 22 222
F: ++49-(0)89-306 22 601




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Execute a function

2012-07-20 Thread Carla Moreira
Yes, I do.

But I need to control how the permutations are done.

Thank you.

2012/7/20 Jessica Streicher j.streic...@micromata.de

 You mean executing the function for all combinations of values?
 For example, if you have a-b-c-1:2
 you would get back the values of

 myfunc(1,1,1)
 myfunc(1,1,2)
 myfunc(1,2,1)
 myfunc(1,2,2)
 myfunc(2,1,1)
 myfunc(2,1,2)
 myfunc(2,2,1)
 myfunc(2,2,2)

 ?

 On 20.07.2012, at 13:05, carla moreira wrote:

 
  Hi,
 
  I would like to evaluate a function, with 3 arguments, for instance,
 
  myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
 }
 
  How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z
 are
  vectors?
 
  Thank you very much in advance
 
 
 
  --
  View this message in context:
 http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.




-- 
Carla Moreira

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Execute a function

2012-07-20 Thread Jessica Streicher
Well, what do you want to control there?

Need a subset? Need an ordering?


On 20.07.2012, at 15:00, Carla Moreira wrote:

 Yes, I do.
  
 But I need to control how the permutations are done.
  
 Thank you.
 
 2012/7/20 Jessica Streicher j.streic...@micromata.de
 You mean executing the function for all combinations of values?
 For example, if you have a-b-c-1:2
 you would get back the values of
 
 myfunc(1,1,1)
 myfunc(1,1,2)
 myfunc(1,2,1)
 myfunc(1,2,2)
 myfunc(2,1,1)
 myfunc(2,1,2)
 myfunc(2,2,1)
 myfunc(2,2,2)
 
 ?
 
 On 20.07.2012, at 13:05, carla moreira wrote:
 
 
  Hi,
 
  I would like to evaluate a function, with 3 arguments, for instance,
 
  myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
 }
 
  How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z are
  vectors?
 
  Thank you very much in advance
 
 
 
  --
  View this message in context: 
  http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
 -- 
 Carla Moreira


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Execute a function

2012-07-20 Thread Peter Ehlers

On 2012-07-20 04:05, carla moreira wrote:


Hi,

I would like to evaluate a function, with 3 arguments, for instance,

myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
 }

How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z are
vectors?


Is this what you have in mind:

  myfunc - function(a, b, c){ sqrt(a)-exp(b)+4*c }
  myfunc2 - function(x){
a - x[1]
b - x[2]
c - x[3]
myfunc(a, b, c)
  }

  x - c(1, 4, 9)
  y - 1:2
  z - c(10, -10, 2, 20)
  d - expand.grid(x, y, z)
  d$value - apply(d, 1, myfunc2)

?

Peter Ehlers



Thank you very much in advance



--
View this message in context: 
http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Execute a function

2012-07-20 Thread Bert Gunter
Inline.

-- Bert

On Fri, Jul 20, 2012 at 6:59 AM, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2012-07-20 04:05, carla moreira wrote:


 Hi,

 I would like to evaluate a function, with 3 arguments, for instance,

 myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
  }

 How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z are
 vectors?


 Is this what you have in mind:

   myfunc - function(a, b, c){ sqrt(a)-exp(b)+4*c }
   myfunc2 - function(x){
 a - x[1]
 b - x[2]
 c - x[3]
 myfunc(a, b, c)
   }

   x - c(1, 4, 9)
   y - 1:2
   z - c(10, -10, 2, 20)
   d - expand.grid(x, y, z)

Peter, what's wrong with
with(d,myfunc(x,y,z))??

I realize this depends on the function be vectorizable, but isn't that
the point? It could be orders of magnitude faster than looping via
apply.

-- Bert

   d$value - apply(d, 1, myfunc2)

 ?

 Peter Ehlers


 Thank you very much in advance



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Execute a function

2012-07-20 Thread Peter Ehlers

Bert,

The only thing wrong is that I'm still 75% asleep! Yikes!!
Thanks for the heads-up.

Carla: See Bert's solution.

Peter Ehlers

On 2012-07-20 07:10, Bert Gunter wrote:

Inline.

-- Bert

On Fri, Jul 20, 2012 at 6:59 AM, Peter Ehlers ehl...@ucalgary.ca wrote:

On 2012-07-20 04:05, carla moreira wrote:



Hi,

I would like to evaluate a function, with 3 arguments, for instance,

myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
  }

How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z are
vectors?



Is this what you have in mind:

   myfunc - function(a, b, c){ sqrt(a)-exp(b)+4*c }
   myfunc2 - function(x){
 a - x[1]
 b - x[2]
 c - x[3]
 myfunc(a, b, c)
   }

   x - c(1, 4, 9)
   y - 1:2
   z - c(10, -10, 2, 20)
   d - expand.grid(x, y, z)


Peter, what's wrong with
with(d,myfunc(x,y,z))??

I realize this depends on the function be vectorizable, but isn't that
the point? It could be orders of magnitude faster than looping via
apply.

-- Bert


   d$value - apply(d, 1, myfunc2)

?

Peter Ehlers



Thank you very much in advance



--
View this message in context:
http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Execute a function

2012-07-20 Thread carla moreira
Yes,

that's this.

Thank you very much.



2012/7/20 Peter Ehlers [via R] ml-node+s789695n463721...@n4.nabble.com

 On 2012-07-20 04:05, carla moreira wrote:

 
  Hi,
 
  I would like to evaluate a function, with 3 arguments, for instance,
 
  myfunc-function(a,b,c) { sqrt(a)-exp(b)+4*c
   }
 
  How to execute  myfunc(x,y,z), for all x, all y and all z, where x,y,z
 are
  vectors?

 Is this what you have in mind:

myfunc - function(a, b, c){ sqrt(a)-exp(b)+4*c }
myfunc2 - function(x){
  a - x[1]
  b - x[2]
  c - x[3]
  myfunc(a, b, c)
}

x - c(1, 4, 9)
y - 1:2
z - c(10, -10, 2, 20)
d - expand.grid(x, y, z)
d$value - apply(d, 1, myfunc2)

 ?

 Peter Ehlers

 
  Thank you very much in advance
 
 
 
  --
  View this message in context:
 http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  [hidden email] 
  http://user/SendEmail.jtp?type=nodenode=4637212i=0mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

 __
 [hidden email] http://user/SendEmail.jtp?type=nodenode=4637212i=1mailing 
 list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 --
  If you reply to this email, your message will be added to the discussion
 below:
 http://r.789695.n4.nabble.com/Execute-a-function-tp4637182p4637212.html
  To unsubscribe from Execute a function, click 
 herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4637182code=Y2FybGFtZ21tQGdtYWlsLmNvbXw0NjM3MTgyfDE3NjAxODQ0MA==
 .
 NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml




-- 
Carla Moreira




--
View this message in context: 
http://r.789695.n4.nabble.com/Execute-a-function-tp4637182p4637213.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.