Simple Function doesn't work?
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 the assignment in the for loop,
ReturnsGrid = function(x,y,m){
grid <- vector(length = m)
for (i in 1:m){
grid[i] <- x + (i-1)*(y-x)/m
}
grid
}
ReturnsGrid(0,9,3)
HTH,
baptiste
2009/11/27 Anastasia <nastik1 at gmail.com>:
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.