[英]R how to create new column based on having values above and below a certain threshold
How do I create a column called "northsouth" that tells me if an ID visits latitudes that are both above and below 35.如何创建一个名为“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"))
You could do你可以做
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
Created on 2022-07-24 by the reprex package (v2.0.1)由代表 package (v2.0.1) 于 2022 年 7 月 24 日创建
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.