![](/img/trans.png)
[英]How to create a column based on values in the rows above/below the row in a different column in R
[英]R how to create new column based on having values above and below a certain threshold
如何創建一個名為“northsouth”的列,告訴我 ID 是否訪問了高於和低於 35 的緯度。
df_input <- data.frame (ID = c(12, 12, 12, 12, 13, 13), lat = c(32, 34, 40, 39, 32, 30))
df_result <- data.frame (portID = c(12, 13), northsouth = c("yes", "no"))
你可以做
library(tidyverse)
df_input %>%
group_by(ID) %>%
summarize(northsouth = max(lat) > 35 & min(lat) < 35)
#> # A tibble: 2 x 2
#> ID northsouth
#> <dbl> <lgl>
#> 1 12 TRUE
#> 2 13 FALSE
由代表 package (v2.0.1) 於 2022 年 7 月 24 日創建
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.