I'm trying to find a simple way of replace the value in the FX.SPOT column based on a string (without looping through the data).
my data structure looks like this:
test = structure(list(FX.QUOTATION = c("AUD-USD", "JPY-USD", "AUD-USD",
"AUD-USD", "AUD-USD", "AUD-USD"), CURRENCY = c("AUD", "JPY",
"AUD", "AUD", "AUD", "AUD"), FX.SPOT = c(0.7016, 115.455, 0.7016,
0.7016, 0.7016, 0.7016)), row.names = c(NA, 6L), class = "data.frame")
and I've been trying to find a way to convert the FX.SPOT value when FX.QUOTATION = 'JPY-USD' so that the value in the FX.SPOT column changes from JPY to -1/JPY.
I tried the below which obviously doesn't work, and could make it work via a loop but think there must be a more efficient method?
within(test, FX.SPOT[FX.QUOTATION %in% 'JPY-USD'] <- -1/FX.SPOT)