[R] Simple Function doesn't work?

Ista Zahn istazahn at gmail.com
Fri Nov 27 17:16:29 CET 2009


Hi,
You need to create the grid object before you can assign values to it. Try

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

On Fri, Nov 27, 2009 at 11:00 AM, Anastasia <nastik1 at gmail.com> 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 at 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org




More information about the R-help mailing list