I have the D
Data.frame
that has values for Stations
. I do have another data.frame
F
that has Stations
threshold values for certain conditions (Ie., WBN, AN etc)
. I would like to use the value of each Stations
in D
to see under which conditions it falls in F
and save the D
data.fram
e with an added column for Conditions
in DF
. Here is my sample code
library(tidyverse)
set.seed(123)
D <- data.frame(Stations = c("A","S","D","Z"), Value = c(15,10,25,16))
F <- data.frame(Stations = c("A","S","D","Z"), WBN = runif(4, 0, 3), BN = runif(4, 3,6),
N = runif(4,7,10), AN = runif(4,15,25))
Desired output I should get a data.frame like below
DF <- D %>% mutate(Condition = c("AN", "AN", "AN", "AN" ))
Sample from my actual data.frame
data.frame Freq
can be considered as F
in the example above while Max_2020
can be considered as the D
.
> head(Freq, 5)
# A tibble: 5 x 9
Stations `1:2` `1:5` `1:10` `1:25` `1:50` `1:100` `1:200` `1:500`
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 05EF001 911 1550 2180 3350 4410 5860 7730 11100
2 05EG004 2.7 6.6 11 18 24 33 43 60
3 05FF003 7.24 35.409999999999997 63.26 100.17 124.95 145.86000000000001 162.72999999999999 179.29
4 05GC006 12.44 38.85 63.11 98.12 125.51 152.86000000000001 179.63 213.48
5 05GD002 1.38 4.03 6.33 9.65 12.33 15.14 20.170000000000002 29.56
> head(Max_2020, 5)
# A tibble: 5 x 2
Stations Value
<chr> <dbl>
1 05EG004 9.18
2 05FF003 38.7
3 05GC006 15.8
4 05GD002 2.65
5 05GF002 57.2
My goal is to add another column in Max_2020
and fill it out based on the condition that where the Value
lies in Freq
. in other words, for example, if the Value
in Max_2020
is less than the number under column 1:2
in Freq
, i would assign 1:2
to the new column in Max_2020
for a particular station. The Value in Max_2020
needs to be checked across all the columns in Freq
for a particular stations
and then assigned its respective condition.