I have a data set of 144 scenarios and would like to calculate the percent change of all possible combinations using the comb n function. I have tried to use a percent difference function within the combn but it keeps giving me a large amount of NA's. Is there a way that I can accomplish this?
create percent change function:
pcchange=function(x,lag=1)
c(diff(x,lag),rep(NA,lag))/x*100
use withing combn:
Catch_comp<-combn(catch_table$av_muC, 2, pcchange)
convert results into a matrix
inputs <- headers
out2 <- Catch_comp
class(out2) <- "dist"
attr(out2, "Labels") <- as.character(inputs)
attr(out2, "Size") <- length(inputs)
out2 <- as.matrix(out2)
out2
This is what my table is coming out looking like:
> out2
F_R1S2_11 F_R1S2_12 F_R1S2_13 F_R1S2_21 F_R1S2_22 F_R1S2_23 F_R1S2_31 0.00000000 -0.8328001 NA -2.1972852 NA -0.11300746 NA -1.15112915 NA -2.7011787 NA -0.5359923 NA
F_R1S2_12 -0.83280008 0.0000000 NA -1.4558031 NA
As an example: I have the average of 1000 simulations of the actual catch for two scenarios-
F_R1S1_11=155420.36
and
F_R1S1_12= 154126.0215.
Using the pcchange function I would like to calculate:
((F_R1S1_11-F_R1S1_12)/F_R1S1_11)*100
or
((155420.36-154126.02)/155420.36)*100=0.83%
change in the values.
I would like to do this for all possible combinations in a 144x144 matrix form. I hope that helps.
Thanks!