@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
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
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 + (
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
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
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
6 matches
Mail list logo