Reputation: 563
I'm trying to figure out an elegant way to do the following:
I have two data frames:
multipFactors
:
structure(list(Library = c("FT259", "EL259", "FT261", "EL261",
"FT325", "EL325"), Vol = c(2.5, 1, 2.5, 1, 2.5, 1), Dfactor = c(5000L,
1000L, 5000L, 1000L, 5000L, 1000L)), .Names = c("Library", "Vol",
"Dfactor"), row.names = c(NA, 6L), class = "data.frame")
and concvals
structure(list(FT265 = c(1.87143067658684, 6.42164423157045,
3.2067011263946, 38.6127973672561, 31.413779293588, 35.5528208255031
), EL265 = c(17.1144442552411, 17.3273656558687, 14.7909715401529,
NaN, NaN, NaN), FT325 = c(35.3550952814249, 37.9458212939415,
29.8197141318635, 35.1760971346751, 36.7065424286613, 42.9943003679566
), wellid = structure(c("A1", "B1", "C1", "D1", "E1", "F1"), .Dim = c(6L,
1L))), .Names = c("FT265", "EL265", "FT325", "wellid"), row.names = c(NA,
6L), class = "data.frame")
I am trying to find a way to select the correct Dfactor
from multipFactors
based on the column name of concvals
and multiply say concvals['FT325']
by the appropriate Dfactor
. The multiplication can either be done in place or into a new data frame, I don't mind.
Is there an "R" way to do something like this, or would it be an occasion for a loop?
Sorry -- just looking at the example, DFactor
is not a factor in the R sense, it's short for dilution factor, so is actually a number. In this example it looks there are only two dilution factors (5000, 1000) but there could be others. Sorry for the lack of clarity.
Thanks H
Upvotes: 1
Views: 1100
Reputation: 81693
This should work:
mapply("*", concvals[multipFactors$Library], multipFactors$Dfactor)
Upvotes: 2