简体   繁体   English

R 如何根据高于和低于某个阈值的值创建新列

[英]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.

相关问题 如何基于R中不同列中行上方/下方的行中的值创建列 - How to create a column based on values in the rows above/below the row in a different column in R R:如何创建一个基于另一列某些值的新列? - R: How to create a new column with values based on certain values of another column? 根据它们是否高于或低于某个阈值来更改矩阵中的值 - Changing values in a matrix depending on whether they are above of below a certain threshold value 在 R 中对高于和低于特定阈值的值进行分组 - Group rows of values above and below specific threshold in R 如果高于 R 中的某个阈值,则有条件地将数据帧中的值乘以另一个数据帧 - Conditionally multiply values in a dataframe by another dataframe if above a certain threshold in R 如何基于R中的另一列创建具有多个值的新列 - How to create a new column with multiple values based on another column in R 如果行值高于某个阈值,则返回列标题 - Return column header if row values are above a certain threshold 如何根据 R 中的最小值和列值创建新字段 - How to create new fields based on min vals and column values in R 如何根据缺失值在 R 中创建新列 - How to create new column in R based on missing values 如何根据 R 中的行值组合创建新变量(列)? - How to create a new variable (column) based on a combination of row values in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM