分为两组数据

时间:2016-04-12 18:02:19

标签: r

我有这些数据:

x1 = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
  17, 18, 19, 20, 21, 22)
y1 = c(1, 6, 2, 5, 4, 7, 9, 6, 8, 4, 5, 6, 5, 5, 6, 7, 5, 8, 9, 
  5, 4, 7)

plot(x1, y1)
fit <- lm(y1 ~ x1)
fit
abline(fit, col = "black")

prediction <- predict(fit)`

我想使用下一个条件将数据分成两组:

    if (y1 < prediction) {print("Negative number")} 
    else if (y1 > prediction) {print("Positive number")}

但似乎:警告信息:

1: In if (y1 < prediction) { :
  the condition has length > 1 and only the first element will be used
2: In if (y1 > prediction) { :
    the condition has length > 1 and only the first element will be used

有人可以告诉我如何解决它吗?

0 个答案:

没有答案