所以我有一些代码可以查看两个数据帧,并为某些分子组合减去一个名为“强度”的列值。但是,例如,如果分子不在另一个数据框中,由于某种原因,它完全摆脱了该行,不太清楚为什么。
blankdata3 和 data3 是我要减去的两个数据框。所以我减去一个分子的强度,例如
(data3 - blankdata3) = 减去数据
#This is my code that subtracts the molecule's Intensity based on if they have the same Composition.
datasubtracted <- blankdata3 %>% left_join(select(data3, Intensity, Composition), by ="Composition") %>%
mutate(Intensity = ifelse (is.na(Intensity.y), -Intensity.x, Intensity.y - Intensity.x)) %>%
select(-Intensity.y, -Intensity.x ) %>%
bind_rows(anti_join(data3, blankdata3, by = "Composition") %>%
mutate( Intensity = -Intensity))
#Example of data3 is below
#Composition Intensity
#C2H6O 100000
#C2H4O2 43000
#Example of blankdata3 is below
#Composition Intensity
#C2H6O 60000
#C3H8 53000
#When I run the code it gives me something like this (datasubtracted)
#Composition Intensity
#C2H6O 40000
#I expect to see this. I want compounds from data3 to carry over to datasubtracted untouched since there is nothing to subtract with. Basically subtracting a molecule by zero.
#Composition Intensity
#C2H6O 40000
#C2H4O2 43000
如果代码运行时在空白数据 3 中找不到分子,则代码完全摆脱了数据 3 中的分子,这是我不想要的。