[R] plot a function with a vector as argument
chaij
azraelchai at hotmail.com
Sun May 18 05:54:31 CEST 2008
I tried to define a function using another function I defined before, and the
previous function has a vector as an argument, when I tried to get the graph
of the new function, there was something going wrong. Here is a simple
example to explain how it happend:
fr1 <- function(x,y){
x^2+x*y+1
}
fr2 <- function(x){
fr1(x,3)
}
plot(fr2)
In this case, it worked just fine. But when I changed it to the following
form:
Fr1 <- function(x){
x1 <- x[1]
x2 <- x[2]
x1^2+x1*x2+1
}
Fr2 <- function(x){
Fr1(c(x,3))
}
plot(Fr2)
it gives:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
Could anyone help me with this problem? Thanks.
--
View this message in context: http://www.nabble.com/plot-a-function-with-a-vector-as-argument-tp17299015p17299015.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list