Re: [R] creating a function

2012-12-23 Thread Jeff Newmiller
r of random errors. > >Any suggestion is very appreciated. > >thanks and best regards, >Simone > >From: Rui Barradas >Sent: Saturday, December 22, 2012 8:29 PM >To: Simone Gogna >Cc: r-help@r-project.org >Subject: Re: [R] creating a function > >Hello, > >I

Re: [R] creating a function

2012-12-23 Thread Rui Barradas
as Sent: Saturday, December 22, 2012 8:29 PM To: Simone Gogna Cc: r-help@r-project.org Subject: Re: [R] creating a function Hello, It's a bad idea to name a function and one of it's arguments Y, use Yfun and Y. What does summation(x(Y.t, Y.t-1, ...)) mean? Is there a multiplication sign be

Re: [R] creating a function

2012-12-23 Thread Simone Gogna
agged values of Y_t+1 from Y_t to Y_t-n. Epsilon_t is, as You said a vector of random errors. Any suggestion is very appreciated. thanks and best regards, Simone From: Rui Barradas Sent: Saturday, December 22, 2012 8:29 PM To: Simone Gogna Cc: r-help@r-project.org Subject: Re: [R] creating a f

Re: [R] creating a function

2012-12-22 Thread Rui Barradas
Hello, It's a bad idea to name a function and one of it's arguments Y, use Yfun and Y. What does summation(x(Y.t, Y.t-1, ...)) mean? Is there a multiplication sign between x and (Y.t, ...)? And is epsilon a vector of errors, one for each Y.t? If so, the following might do it. Yfun <- function(

[R] creating a function

2012-12-22 Thread Simone Gogna
Dear R users, I’d like to create a function as: Y.t+1 = Y.t + (1\p)*summation(x(Y.t,Y.t-1,...)) + epsilon.t where x is a function of Y.t, Y.t-1 and so on, epsilon is a random error and p is a parameter. Do you think something of the following form might be appropriate? Y<-function(Y,p,x,epsi

Re: [R] creating a function using for if

2012-10-22 Thread Sarah Goslee
Then what about: fun<-function(a,b,c,data) { ifelse(data > c, (a*(data-c)^0.5)+(b*(data-c)), 0) } y=c(100,210,320,130,170,120,220,90,55,45) fun(1,0.2,150,data=y) > fun(1,0.2,150,data=y) [1] 0.00 77471.67 130418.05 0.00 44725.36 0.00 83680.00 [8] 0.00 0

Re: [R] creating a function using for if

2012-10-22 Thread jim holtman
Try this -- this uses the vectorization which you need to read up on in the Intro to R: > #set the function > fun<-function(a,b,c,data) + { + N <- numeric(length(data)) # initialize to zero + indx <- data > c # determine which data is greater than c + N[indx] <- (a * (data[indx] - c) ^ 0.5) + (b

Re: [R] creating a function using for if

2012-10-22 Thread Balqis
thank you. yes I want to loop over the elements of the data. I want the output to be corresponded to the input by unchanging index. at the same time, the data that is more than c value should follow the function (a*(data-c)^0.5)+(b*(data-c), and the rest (same or less than c) should return a zero.

Re: [R] creating a function using for if

2012-10-22 Thread Sarah Goslee
N=as.vector() This doesn't mean anything in R: you can read the help using ?as.vector to see what the required arguments are. Do you want to loop over the elements of data? That's not what your loop is doing. Instead it is looping over each element of the sequence from the min to the max *value*

[R] creating a function using for if

2012-10-22 Thread Balqis
Hi all, I'm trying to create a function where it can process a vector and also give a vector output accordingly #input: a,b anc c are constants, data is the vector #set the function fun<-function(a,b,c,data) { N=as.vector() for (i in min(data):max(data)){ if(i>c){ N<-(a*(i-c)^0.5)+(b*(i-c))} else