如何在R中创建连接两点的线

Uda*_*rya 5 graphics visualization r lines

有没有办法在 R 中创建连接两点的线?我知道lines(),函数,但它创建线段我正在寻找的是一条无限长的线。

Mar*_*box 6

以下是 Martha 建议的示例:

set.seed(1)
x <- runif(2)
y <- runif(2)

# function
segmentInf <- function(xs, ys){
  fit <- lm(ys~xs)
  abline(fit)
}

plot(x,y)
segmentInf(x,y)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明