请给我一个技术问题:
lonlon <- c(3.581667, 3.146667, 3.256667, 2.860000, 3.473333, 2.981667, 3.465000, 2.703333, 3.521667, 3.320000, 3.196667, 3.961667, 3.686667, 3.305000, 3.413333, 3.250000, 3.325000, 3.856667, 3.028333, 3.211667, 3.993333, 3.045000, 3.728333, 3.515000, 2.755000, 3.691667, 2.675000, 4.096667, 3.853333, 2.880000, 3.750000, 3.565000, 2.961667, 3.165000, 4.166667, 3.145000, 2.740000, 3.145000, 3.346667, 3.400000, 3.351667, 3.245000, 3.108333, 3.301667, 3.506667, 2.856667, 3.308333, 3.456667, 2.975000, 3.320000, 3.201667, 3.398333, 3.303333)
lala <- c(43.68167, 43.33667, 43.65333, 43.62000, 43.59500, 43.68333, 43.38833, 43.60167, 43.58167, 43.73833, 43.71167, 43.57667, 43.63500, 43.65500, 43.45667, 43.62167, 43.76333, 43.71667, 43.50167, 43.80000, 43.72833, 43.65500, 43.77833, 43.84167 ,43.48833, 43.39667 ,43.32667, 43.72000, 43.53667, 43.36333 ,43.94667, 43.32833 ,43.49000 ,43.27333 ,43.63333 ,43.47500, 43.41667, 43.64000, 43.70667, 43.43667 ,43.32167 ,43.78500 ,43.58333, 43.55000 ,43.66333, 43.38500, 43.86667, 43.79167, 43.66667, 43.49167 ,43.30167, 43.65500, 43.41167)
lulu <- c(round(runif(53), digits=5))
lulu <- paste("town_",lulu, sep = "")
lili <- cbind.data.frame( lulu, lonlon, lala)
plot(lili$lonlon, lili$lala)
abline(b = 0.7, a = 41.25)
所以,我要创建2种类型的点。类型1:指向顶部/左侧,类型2:指向底部/右侧。我的线性方程是:y = 0.7x + 41.25。
在以前的操作中,我使用了:
lili2 <- lili %>% mutate(type= case_when(
lonlon < 3.35 ~ 1,
lonlon > 3.35 & lala < 43.59 ~ 2,
lonlon > 3.35 & lala > 43.59 ~ 3
))
可以按照我的对角线(线性方程式)进行相同的操作吗?谢谢
答案 0 :(得分:1)
require(dplyr)
lili <-
lili %>%
mutate(point_type = if_else (lala >= (.7*lonlon + 41.25),1,2))