Re: [R] Simple Function doesn't work?

2009-11-27 Thread Colin Millar
@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Colin Millar Sent: 27 November 2009 16:41 To: Anastasia; r-help@r-project.org Subject: Re: [R] Simple Function doesn't work? Hi, You would also make your code more efficient and possible more readable by doing ReturnsGrid

Re: [R] Simple Function doesn't work?

2009-11-27 Thread Colin Millar
oun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Anastasia Sent: 27 November 2009 16:01 To: r-help@r-project.org Subject: [R] Simple Function doesn't work? Hello, I am new to R program, therefore, I am sorry if this is a really stupid question. I wrote a simple func

Re: [R] Simple Function doesn't work?

2009-11-27 Thread Alain Guillet
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 + (

Re: [R] Simple Function doesn't work?

2009-11-27 Thread baptiste auguie
Hi, The error message, Error in grid[i] <- x + (i - 1) * (y - x)/m : object of type 'closure' is not subsettable indicates that "grid" is actually known to R as a function (type grid to see its definition). You can define your own variable with the same name, but that needs to be done before t

Re: [R] Simple Function doesn't work?

2009-11-27 Thread Ista Zahn
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 wrote: > Hello, > > I am new to R program, therefore, I am sorry i

[R] Simple Function doesn't work?

2009-11-27 Thread Anastasia
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! [[alternati