我有8个组(列),每个组由8个不同的分子组成。
在数据框中,数字表示每个分子中的碳数,每列为一组。我需要找到每个分子要使用的浓度,以便每个基团末端的碳原子总数相同。我应该按比例(20%mol1、25%mol2等)获得此结果。只要将每个值乘以其比例,每列的最终碳原子数就无关紧要。
我将不胜感激!谢谢
data.frame(c(36, 12, 14, 4, 3, 8, 4 ,7), c(6, 12, 3, 4, 6, 4,
8, 7), c(36, 7, 6, 4, 9, 8, 4, 7), c(6, 12, 12, 5, 4, 7,
8,7), c( 36, 6, 3, 6, 4, 9, 4, 7), c(36, 5, 4, 6, 6, 3, 8,
7),c(36, 12, 12, 14, 4, 6, 4, 7), c( 6, 6, 3, 4, 6, 8, 4, 7))
答案 0 :(得分:0)
您可以找到列总和的最小公倍数,并找到必要的比例,如下所示:
df <- structure(list(a = c(36, 12, 14, 4, 3, 8, 4, 7), b = c(6, 12,
3, 4, 6, 4, 8, 7), c = c(36, 7, 6, 4, 9, 8, 4, 7), d = c(6, 12,
12, 5, 4, 7, 8, 7), e = c(36, 6, 3, 6, 4, 9, 4, 7), f = c(36,
5, 4, 6, 6, 3, 8, 7), g = c(36, 12, 12, 14, 4, 6, 4, 7), h = c(6,
6, 3, 4, 6, 8, 4, 7)), class = "data.frame", row.names = c(NA,
-8L))
library(numbers)
c_amt <- colSums(df)
LCM_c <- Reduce(LCM, c_amt, 1)
odds <- LCM_c / c_amt
props <- odds / sum(odds)
library(scales)
percent_format()(props)
# [1] "9.5%" "16.7%" "10.3%" "13.7%" "11.1%" "11.1%" "8.8%" "18.9%"