我有以下定义:
label id_row ID Well WT_group_1 WT_group_2 WT_group_3 WT_group_4
<chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
1 well_1 169 PBS H1 2728. 2521 2360. 2670
2 well_2 361 PBS H1 2688 2534 2418 NA
3 well_3 553 PBS H1 3221 3320.5 2835 3247
4 well_4 745 PBS H1 2838 3362 2832. 2975
5 well_5 937 PBS H1 2857 2654 NA 2637
6 well_6 1129 PBS H1 2834 2678 2287 2713
7 well_7 1189 PBS B7 2374 2625 2444 2622
行well_1-well_2, well_3-well_4, well_5-well_6
是相关的.然而,因为well_7
是单独的,所以如果我有NA值,我不需要将它与任何行相关联.
我需要用相关行的值替换NA.例如:
well_1 2670
well_2 NA
after the operation:
well_1 2670
well_2 2670
or
for well_4 and 5:
well_4 2832.
well_5 NA
after the operation:
well_4 2832.
well_5 2832.
我试着用这个来做这个手术:
pbs_in_v2 %>%
group_by(label) %>%
fill(everything(), .direction = "downup") %>%
ungroup()
然而,使用这个 idea 涉及group_by
,当我需要做的时候,有特定的条件:
well_1-well_2, well_3-well_4, well_5-well_6 and for well_7, leave it like that.
我认为完成if_else
分可能会对此有所裨益.然而,如果我需要使用if,我如何实现我的目标?
有没有一种方法来执行任务与我的主要 idea ,这涉及group_by
和fill
有什么主意吗?