用 r 在一条线上找到一个点

Finding a point on a line with r

好的,所以这可能是有史以来最基本的问题,但我真的无法在任何地方找到如何做! 一条线已经画好了。我被要求找出当我的 X 坐标为 6 时我的 Y 点是什么。我如何找到我的 Y 坐标?

拟合您的数据并获得截距和斜率。用它来计算您的 Y 轴值。

library(tidyverse)
library(ggplot)

Data <- tibble(`Prosocial Behaviour` = c(0:9),
               `Money` = seq(0,18,2)) # sample data

Fit <- lm(`Prosocial Behaviour` ~ Money, data = Data) %>%
  broom::tidy() %>%
  pull(estimate) # obtain the slope and intercept

#this takes the form of Y = c + mx
Y <- Fit[1] + Fit[2]*6 # since you want to find Y given x = 6