Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从函数打印值_R - Fatal编程技术网

R 从函数打印值

R 从函数打印值,r,R,我正在R中寻找一种方法,从a到b范围内的函数中获取整数的所有数字 pfA <- function(x) { return ( 123 * x ) ; } p_a = Vectorize(pfA, "x") plot(0,0, col="purple", type="l", xlim=c(-5,5000), ylim=c(-5,5000)) curve (p_a(x), col="red", add=TRUE) print_values((p_a(x),a,b) 我修改了曲线函数的代码

我正在R中寻找一种方法,从
a
b
范围内的函数中获取整数的所有数字

pfA <- function(x) {  return (  123 * x ) ; }
p_a = Vectorize(pfA, "x")
plot(0,0, col="purple", type="l", xlim=c(-5,5000), ylim=c(-5,5000))
curve (p_a(x), col="red", add=TRUE)
print_values((p_a(x),a,b)

我修改了
曲线
函数的代码以创建
myfun

myfun <-
function (expr, from, to) 
{
  sexpr <- substitute(expr)
  x <- seq.int(from, to)
  ll <- list(x = x)
  y <- eval(sexpr, envir = ll)
  cbind(x = ll[["x"]], y)
}
myfun
myfun <-
function (expr, from, to) 
{
  sexpr <- substitute(expr)
  x <- seq.int(from, to)
  ll <- list(x = x)
  y <- eval(sexpr, envir = ll)
  cbind(x = ll[["x"]], y)
}
a <- -5
b <- 5
myfun(p_a(x), a, b)

#        x    y
#  [1,] -5 -615
#  [2,] -4 -492
#  [3,] -3 -369
#  [4,] -2 -246
#  [5,] -1 -123
#  [6,]  0    0
#  [7,]  1  123
#  [8,]  2  246
#  [9,]  3  369
# [10,]  4  492
# [11,]  5  615