Hi,

If you execute the following code it works but I wouldn't use grid if I were you as a vector as this name is already used by R (check help(grid)) and it explains why you have to define it in the function.

ReturnsGrid = function(x,y,m){
grid <- numeric(m)
for (i in 1:m){
  grid[i] <- x + (i-1)*(y-x)/m
}
grid
}

xx=ReturnsGrid(0,9,3)

Regards,
Alain


Anastasia wrote:
Hello,

I am new to R program, therefore, I am sorry if this is a really stupid
question.
I wrote a simple function and for some reason it doesn't work

ReturnsGrid = function(x,y,m){
for (i in 1:m){
   grid[i] <- x + (i-1)*(y-x)/m
}
grid
}

xx=ReturnsGrid(0,9,3)

Thanks a lot!

        [[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.


--
Alain Guillet
Statistician and Computer Scientist

SMCS - Institut de statistique - Université catholique de Louvain
Bureau c.316
Voie du Roman Pays, 20
B-1348 Louvain-la-Neuve
Belgium

tel: +32 10 47 30 50

______________________________________________
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.

Reply via email to