我想按某些列的顺序(序列)对向量中的每个值取幂,并在每个值的新列中输入结果。我的数据是:
df6 <- structure(list(Samples = c("S1", "S1", "S1", "S2", "S2", "S2",
"S3", "S3", "S3", "S4", "S4", "S4"), GOI_A_Ct = c(33.67, 33.67,
33.67, 19.5, 19.5, 19.5, 16.03, 16.03, 16.03, 13, 13, 13), GOI_B_Ct = c(30.46,
30.34, 30.58, 30.34, 30.5, 30.43, 27.06, 27.03, 27.03, 27.1,
26.99, 27.045), Mean_REF_Ct = c(25.1553175293018, 25.0150674594333,
24.9249052154667, 25.1052285390912, 25.1452997595972, 25.1352819757408,
24.2135829649393, 24.0632936232761, 24.0733130250076, 24.0532742053967,
24.0632936232761, 24.2135829649393), delta_GOI_A_Ct = c(0, 0,
0, -14.17, -14.17, -14.17, -17.64, -17.64, -17.64, -20.67, -20.67,
-20.67), delta_GOI_B_Ct = c(0, -0.120000000000001, 0.119999999999997,
-0.120000000000001, 0.0399999999999991, -0.0300000000000011,
-3.4, -3.43, -3.43, -3.36, -3.47, -3.415), delta_Mean_REF_Ct = c(0.123554127901208,
-0.0166959419673027, -0.106858185933909, 0.0734651376905866,
0.113536358196594, 0.103518574340168, -0.81818043646129, -0.968469778124522,
-0.958450376393031, -0.978489196003963, -0.968469778124522, -0.81818043646129
)), class = "data.frame", row.names = c(NA, -12L))
我的vector是:Effi<- c(1.9, 1.8, 1.2)
我的代码是:df7 <- df6 %>% mutate(across(starts_with("delta"), function(x) (Effi^-x), .names = "{sub ('delta', 'FC', .col)}"))
但这段代码并不是按顺序工作的。在Effi向量中,我需要1.9的delta_GOI_A_Ct列的幂、1.8的delta_GOI_B_Ct列的幂和1.2的delta_Mean_REF_Ct列的幂。
我的错误结果是:
structure(list(Samples = c("S1", "S1", "S1", "S2", "S2", "S2",
"S3", "S3", "S3", "S4", "S4", "S4"), GOI_A_Ct = c(33.67, 33.67,
33.67, 19.5, 19.5, 19.5, 16.03, 16.03, 16.03, 13, 13, 13), GOI_B_Ct = c(30.46,
30.34, 30.58, 30.34, 30.5, 30.43, 27.06, 27.03, 27.03, 27.1,
26.99, 27.045), Mean_REF_Ct = c(25.1553175293018, 25.0150674594333,
24.9249052154667, 25.1052285390912, 25.1452997595972, 25.1352819757408,
24.2135829649393, 24.0632936232761, 24.0733130250076, 24.0532742053967,
24.0632936232761, 24.2135829649393), delta_GOI_A_Ct = c(0, 0,
0, -14.17, -14.17, -14.17, -17.64, -17.64, -17.64, -20.67, -20.67,
-20.67), delta_GOI_B_Ct = c(0, -0.120000000000001, 0.119999999999997,
-0.120000000000001, 0.0399999999999991, -0.0300000000000011,
-3.4, -3.43, -3.43, -3.36, -3.47, -3.415), delta_Mean_REF_Ct = c(0.123554127901208,
-0.0166959419673027, -0.106858185933909, 0.0734651376905866,
0.113536358196594, 0.103518574340168, -0.81818043646129, -0.968469778124522,
-0.958450376393031, -0.978489196003963, -0.968469778124522, -0.81818043646129
), FC_GOI_A_Ct = c(1, 1, 1, 8911.24790256821, 4142.01242480709,
13.2433621854489, 82644.4170845227, 31842.4877218358, 24.932003562752,
577879.025429365, 189009.085351031, 43.3187938492919), FC_GOI_B_Ct = c(1,
1.07308148257159, 0.978359013524065, 1.08006634125842, 0.976762774460425,
1.00548463253129, 8.86670466809862, 7.50904474999272, 1.86892414131498,
8.64195696320214, 7.68768522545387, 1.86381994664705), FC_Mean_REF_Ct = c(0.923759338765905,
1.00986196383865, 1.01967357423325, 0.953940589982091, 0.935442913732288,
0.981303324786334, 1.69071631258144, 1.76694774635023, 1.19094387468592,
1.87394735861131, 1.76694774635023, 1.16087256193282)), class = "data.frame", row.names = c(NA,
-12L))
2条答案
按热度按时间qnzebej01#
使用一个命名的vector和
cur_column()
,你可以做到:czq61nw12#
如果base R方法可以,使用
Map
,为了清楚起见,还将使用的 Effi 值放在列名中。