Пересчет весовых процентов оксидов на атомные проценты.
Reference | |
---|---|
Input | wtp |
Results | atp |
elements <- read.csv("constants_elements.csv",stringsAsFactors=F); oxides <- read.csv("constants_oxides.csv",stringsAsFactors=F); recalc.wtp_comp_to_atp <- function (wtp_data, cat_only = F, ...) { data <- wtp_data[,grep("_wtp", names(wtp_data))]; data_atp = data.frame(Name=wtp_data$Name); cF = rep(0, nrow(data)); cCl = rep(0, nrow(data)); cO = rep(0, nrow(data)); for (wtname in names(data)) { oxname <- gsub('_wtp', "", wtname); oxconst = subset(oxides,oxide==oxname) catconst = subset(elements,element==oxconst$cation) anconst = subset(elements,element==oxconst$anion) ddf = data.frame(data[,wtname]/(catconst$weight*oxconst$cation_count+anconst$weight*oxconst$anion_count)*oxconst$cation_count); names(ddf) <- c(oxconst$cation); data_atp = cbind(data_atp, ddf); anc = data[,wtname]/(catconst$weight*oxconst$cation_count+anconst$weight*oxconst$anion_count)*oxconst$anion_count; if(oxconst$anion=="F") {cF = cF + anc} if(oxconst$anion=="Cl") {cCl = cCl + anc} if(oxconst$anion=="O") {cO = cO + anc} } data_atp$Name <- NULL; data_atp$F <- cF; data_atp$Cl <- cCl; data_atp$O <- cO; data_sum <- rowSums(data_atp)[1]; data_atp_ret <- rowApply('/',data_atp,data_sum)*100; names(data_atp_ret) <- paste0(names(data_atp_ret),'_atp'); return(cbind(Name=wtp_data$Name,data_atp_ret)); }