R语言 两表计算

emeijp43  于 2023-02-27  发布在  其他
关注(0)|答案(1)|浏览(185)

我必须使用相同的“参数”变量进行数据框。我想用相同“参数”的第二个表中的值对第一个表中的值进行加权。计算公式为:1-(第一个表中的值/第二个表中“可取性”的值)
第一桌

structure(list(`SE_HMWS (%) (2-8°C)` = c(0.125, 0.125, 0.285714285714286, 
0.125, 0.25, 0.125, 0.222222222222222, 0.125, 0.125, 0.25), `SE_HMWS (%) (25±2°C)` = c(1, 
0.875, 1, 0.875, 1.125, 0.875, 1.11111111111111, 0.875, 0.875, 
1), `SE_HMWS (%) (40±2°C)` = c(5.875, 5.625, 6, 5.375, 6.5, 5.125, 
5.66666666666667, 5.625, 5.375, 5.375), `SE_LMWS (%) (2-8°C)` = c(0.0434782608695652, 
0, 0.0434782608695652, 0.0434782608695652, 0.0434782608695652, 
0.0434782608695652, 0.0434782608695652, 0.0434782608695652, 0.0434782608695652, 
0.0434782608695652), `SE_LMWS (%) (25±2°C)` = c(0.434782608695652, 
0.434782608695652, 0.434782608695652, 0.391304347826087, 0.434782608695652, 
0.434782608695652, 0.478260869565218, 0.434782608695652, 0.434782608695652, 
0.391304347826087), `SE_LMWS (%) (40±2°C)` = c(2.60869565217391, 
2.56521739130435, 2.52173913043478, 2.52173913043478, 2.52173913043478, 
2.47826086956522, 2.52173913043478, 2.52173913043478, 2.56521739130435, 
2.34782608695652), `SE_Monomer (%) (2-8°C)` = c(-0.00206398348813208, 
-0.0010319917440661, -0.00206185567010309, -0.00206185567010309, 
-0.00206611570247939, -0.00206398348813208, -0.00206611570247939, 
-0.00206398348813208, -0.00206398348813208, -0.00206398348813208
), `SE_Monomer (%) (25±2°C)` = c(-0.018575851393189, -0.0175438596491229, 
-0.0175257731958763, -0.0185567010309278, -0.018595041322314, 
-0.0165118679050569, -0.021694214876033, -0.0175438596491229, 
-0.0175438596491229, -0.0175438596491229), `SE_Monomer (%) (40±2°C)` = c(-0.109391124871001, 
-0.107327141382869, -0.104123711340206, -0.105154639175258, -0.112603305785124, 
-0.101135190918473, -0.112603305785124, -0.106295149638803, -0.105263157894737, 
-0.100103199174407)), row.names = c("STD786_F1_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F10_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F2_225mg/mL - 50mM His/His.HCl, 165mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F3_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F4_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 45mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F5_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F6_225mg/mL - 50mM His/His.HCl, 70mM Arg.HCl, 70mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F7_225mg/mL - 50mM His/His.HCl, 150mM Arg.HCl, 200mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F8_225mg/mL - 50mM His/His.HCl, 110mM Arg.HCl, 225mM Pro, 0.02% PS80 - pH5.50-Glass vial", 
"STD786_F9_225mg/mL - 50mM His/His.HCl, 55mM Arg.HCl, 135mM Pro, 0.02% PS80 - pH5.50-Glass vial"
), class = "data.frame")`

第二个表:

structure(list(Parameters = c("SE_HMWS (%) (2-8°C)", "SE_HMWS (%) (25±2°C)", 
"SE_HMWS (%) (40±2°C)", "SE_LMWS (%) (2-8°C)", "SE_LMWS (%) (25±2°C)", 
"SE_LMWS (%) (40±2°C)", "SE_Monomer (%) (2-8°C)", "SE_Monomer (%) (25±2°C)", 
"SE_Monomer (%) (40±2°C)"), Desirability = c(2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L), Importance = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L)), row.names = c(NA, -9L), class = "data.frame")
rsl1atfo

rsl1atfo1#

library(tidyverse)

table1 %>%
  rownames_to_column() %>%
  pivot_longer(-rowname, names_to = "Parameters", values_to = "value") %>%
  left_join(table2, by = "Parameters") %>% 
  mutate(calcul = 1 - value/Desirability) %>%
  select(rowname, Parameters, calcul) %>% 
  pivot_wider(names_from = Parameters, values_from = calcul) %>%
  column_to_rownames(var = "rowname")

相关问题