Re: [R] Apply a multi-variable function to a vector

2016-09-13 Thread S Ellison
> I would like to define an arbitrary function of an arbitrary number of > variables, > for example, for 2 variables: > > func2 <- function(time, temp) time + temp > > I'd like to keep variable names that have a meaning in the problem (time and > temperature above). Not quite enough

Re: [R] Apply a multi-variable function to a vector

2016-09-12 Thread Stephen Kennedy
gt;> although this does work: >> >> do.call(func2, as.list(c(10, 121))) >> >> And, this also works: >> >> apply(expand.grid(temps,times), 1, function(a) do.call("+", as.list(a))) >> >> There is some subtlety here I don't understand.

Re: [R] Apply a multi-variable function to a vector

2016-09-10 Thread Stephen Kennedy
tion(a) do.call("+", as.list(a))) >> >> There is some subtlety here I don't understand. >> >> Thanks, >> >> Steve >> >> -Original Message- >> From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] >> Sent: Friday

Re: [R] Apply a multi-variable function to a vector

2016-09-09 Thread Jeff Newmiller
is.ca.us] Sent: Friday, September 09, 2016 5:39 PM To: Steve Kennedy; r-help@r-project.org Subject: Re: [R] Apply a multi-variable function to a vector Your architecture has a bad smell to me. For one thing you are mixing different units in the same vector but should be putting multiple instance

Re: [R] Apply a multi-variable function to a vector

2016-09-09 Thread Jeff Newmiller
Your architecture has a bad smell to me. For one thing you are mixing different units in the same vector but should be putting multiple instances of the same variable into one vector. Lists of vectors (data frames) are typically used when multiple variables need to be grouped. Another problem

Re: [R] Apply a multi-variable function to a vector

2016-09-09 Thread William Dunlap via R-help
Try do.call(), as in > func2 <- function(time, temp) paste(time, temp) > func2(121, 10) [1] "121 10" > do.call(func2, as.list(c(121,10))) [1] "121 10" > do.call(func2, list(121,10)) [1] "121 10" > > func2(121, time=10:12) [1] "10 121" "11 121" "12 121" > do.call(func2, list(121,time=10:12)) [1]

[R] Apply a multi-variable function to a vector

2016-09-09 Thread Stephen Kennedy
Hello, I would like to define an arbitrary function of an arbitrary number of variables, for example, for 2 variables: func2 <- function(time, temp) time + temp I'd like to keep variable names that have a meaning in the problem (time and temperature above). If I have a vector of values

[R] Apply a multi-variable function to a vector

2016-09-09 Thread Steve Kennedy
Hello, I would like to define an arbitrary function of an arbitrary number of variables, for example, for 2 variables: func2 <- function(time, temp) time + temp I'd like to keep variable names that have a meaning in the problem (time and temperature above). If I have a vector of values for