In this df wb
I calculate the mean of T
based on 2 conditions C2== "B" & C3== "AS1"
. Then I want to filter my data based on the calculated TmeanAS1
plus minus 1. I will then do the same for calculating the TmeanAS1
of C2== "B" & C3== "AS2"
and I need to end up with a wb
than has only rows with a T value in AS1 which is equal to the TmeanAS1 +/- 1 and a T value in AS21 which is equal to the TmeanAS2 +/- 1 etc.
# A tibble: 30 x 4
C1 C2 C3 T
<dbl> <chr> <chr> <dbl>
1 1 A AS1 61.5
2 2 A AS1 61.6
3 3 A AS1 61.9
4 4 B AS1 70.9
5 5 B AS1 70.9
6 6 B AS1 70.9
7 7 B AS1 70.7
8 8 C AS1 70.9
9 9 C AS1 70.9
10 10 C AS1 70.9
# … with 20 more rows
structure(list(C1 = c(1, 2, 3, 4, 5, 6), C2 = c("A", "A", "A",
"B", "B", "B"), C3 = c("AS1", "AS1", "AS1", "AS1", "AS1", "AS1"
), T = c(61.5034980773926, 61.6354866027832, 61.8994636535645,
70.8747406005859, 70.8747406005859, 70.8747406005859)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
My code returns a df with the right Tmean, but the +/- doesn't work. I could also mention that the TmeanAS1 doesn't need to be a df
TmeanAS1 <- wb %>% filter(C2 == "B" & C3 == "AS1") %>% summarise(TmeanAS1=mean(T))
>TmeanAS1
TmeanAS1
1 70.84174
wb_filtered <- wb %>% filter(T<(TmeanAS1$TmeanAS1 %+-% 1))