Пересчет весовых процентов оксидов на атомные проценты.
Reference | |
---|---|
Input | wtp |
Results | atp |
elements <- read.csv("constants_elements.csv",stringsAsFactors=F); recalc.wtp_at_to_atp <- function (wtp_data, ...) { data <- wtp_data[,grep("_wtp", names(wtp_data))]; data_atp = data.frame(Name=wtp_data$Name); mw <- c(); for (wtnamew in names(data)) { wtname <- gsub('_wtp', "", wtnamew); econst = subset(elements,element==wtname) mw <- c(mw,c(1/econst$weight)); } data_st1 <- data/100; data_st2 <- rowApply('*',data_st1,mw); st2_sum <- rowSums(data_st2); data_st3 <- (data_st2/st2_sum)*100; names(data_st3) <- gsub("_wtp", "_atp", names(data_st3)); data_atp <- cbind(data_atp, data_st3); return(data_atp); } recalc.wtp_at_to_atp.test <- function () { td <- data.frame(Name="test", S_wtp=19.87, Fe_wtp=34.32, Co_wtp=0.17, Ni_wtp=0.16, As_wtp=45.29, Sb_wtp=0.37); td <- rbind(td,td) rs <- recalc.wtp_at_to_atp(td); expect_equal(object = rs$As_atp[1], 32.72, tolerance = 0.01); expect_equal(object = rs$As_atp[2], 32.72, tolerance = 0.01); }