monicamir88 wrote > Hello! > I have a doubt with the R software. I have this function: > > results <- function(bCODBOD, BOD, VSS, COD, sBOD, sCOD, TSS, TKNpa, T, > NH3Ne, DO, Q, TKN, MLSS, NO3Ne, RAS, tanoxic1, tanoxic2, rbCOD, SDNR1, > SDNR2, tdanoxic, tanaerobic, IRp, P) { > bCOD <- bCODBOD*BOD > nbCOD <- COD-bCOD > nbVSS <- VSS*(1-((bCODBOD)*(BOD-sBOD)/(COD-sCOD))) > iTSS <- TSS-VSS > SF <- TKNpa > knt <- 0.74*1.053^(T-20) > kdnt <- 0.08*1.04^(T-20) > unmt <- 0.75*1.07^(T-20) > un <- (unmt*NH3Ne)/(knt+NH3Ne)*(DO/(0.5+DO))-kdnt > kst <- 20*1^(T-20) > kdt <- 0.12*1.04^(T-20) > umt <- 6*1.07^(T-20) > SRTtheo <- 1/un > SRT <- SRTtheo*SF > S <- kst*(1+kdt*SRT)/(SRT*(umt-kdt)-1) > Pxbh <- Q*0.4*(bCOD-S)/(1+kdt*SRT) > Pxdead <- 0.15*kdt*Q*0.4*(bCOD-S)*SRT/(1+kdt*SRT) > Nox1 <- 0.8*TKN > Pxbnit1 <- Q*0.12*Nox1/(1+kdnt*SRT) > Pxbio1 <- Pxbh+Pxdead+Pxbnit1 > Nox2 <- TKN-NH3Ne-0.12*Pxbio1/Q > Pxbnit2 <- Q*0.12*Nox2/(1+kdnt*SRT) > Pxbio2 <- Pxbh+Pxdead+Pxbnit2 > Nox3 <- TKN-NH3Ne-0.12*Pxbio2/Q > Pxbnit3<- Q*0.12*Nox3/(1+kdnt*SRT) > Pxbio3 <- Pxbh+Pxdead+Pxbnit3 > Pxvss <- Pxbio3+Q*nbVSS > Pxtss <- Pxbio3/0.88+Q*nbVSS+Q*(TSS-VSS) > MassMLVSS <- Pxvss*SRT > MassMLSS <- Pxtss*SRT > Vaerobic <- MassMLSS/MLSS > taerobic <- Vaerobic/Q > thaerobic <- taerobic*24 > VSSfraction <- MassMLVSS/MassMLSS > MLVSS <- MLSS*VSSfraction > observedyield <- Pxtss/(Q*(bCOD-S))*bCODBOD > Xb <- SRT*Q/Vaerobic*(0.4*bCOD/(1+kdt*SRT)) > IR <- Nox3/NO3Ne-1-RAS > Noxfeed <- (IR*Q+RAS*Q)*NO3Ne > Vanoxic1 <- tanoxic1*Q > Vanoxic2 <- tanoxic2*Q > FMb1 <- Q*BOD/(Vanoxic1*Xb) > FMb2 <- Q*BOD/(Vanoxic2*Xb) > rbCODbCOD <- rbCOD/bCOD > SDNRt1 <- SDNR1*1.026^(T-20) > SDNRt2 <- SDNR2*1.026^(T-20) > NOr1 <- Vanoxic1*SDNRt1*Xb > NOr2 <- Vanoxic2*SDNRt2*Xb > Excesscap1 <- NOr1/Noxfeed > Excesscap2 <- NOr2/Noxfeed > Vanoxic <- tdanoxic*Q > Vanaerobic <- tanaerobic*Q > NO3reac <- NO3Ne*IRp/(1+IRp) > rbCODremov <- NO3reac*6.6 > rbCODava <- rbCOD-rbCODremov > biorem <- rbCODava/10 > Pbiomassg <- (Pxbh+Pxbnit3)*0.015/Q > Premov <- Pbiomassg+biorem > Peff <- P-Premov > > res <- c(bCOD, nbCOD, nbVSS, iTSS, SF, knt, kdnt, unmt, un, kst, kdt, umt, > SRTtheo, SRT, S, Pxbh, Pxdead, Nox1, Pxbnit1, Pxbio1, Nox2, Pxbnit2, > Pxbio2, Nox3, Pxbnit3, Pxbio3 , Pxvss, Pxtss, MassMLVSS, MassMLSS, > Vaerobic, taerobic, thaerobic, VSSfraction, MLVSS, observedyield, Xb, IR, > Noxfeed, Vanoxic1, Vanoxic2, FMb1, FMb2, rbCODbCOD, SDNRt1, SDNRt2, NOr1, > NOr2, Excesscap1, Excesscap2, Vanoxic, Vanaerobic, NO3reac, rbCODremov, > rbCODava, biorem, Pbiomassg, Premov, Peff) > > names(res) <- c("bCOD", "nbCOD", "nbVSS", "iTSS", "SF", "knt", "kdnt", > "unmt", "un", "kst", "kdt", "umt", "SRTtheo", "SRT", "S", "Pxbh", > "Pxdead", "Nox1"," Pxbnit1", "Pxbio1", "Nox2", "Pxbnit2", "Pxbio2", > "Nox3", "Pxbnit3", "Pxbio3" , "Pxvss", "Pxtss", "MassMLVSS", "MassMLSS", > "Vaerobic", "taerobic", "thaerobic", "VSSfraction", "MLVSS", > "observedyield", "Xb", "IR", "Noxfeed", "Vanoxic1", "Vanoxic2", "FMb1", > "FMb2", "rbCODbCOD", "SDNRt1", "SDNRt2", "NOr1", "NOr2", "Excesscap1", > "Excesscap2", "Vanoxic", "Vanaerobic", "NO3reac", "rbCODremov", > "rbCODava", "biorem", "Pbiomassg", "Premov", "Peff") > > return(res) } > > > > Where, for example, the values of the variables are: > results(1.6, 140, 60, 300, 70, 132, 70, 1.5, 12, 0.5, 2, 22464, 35, 3000, > 6, 0.6, 0.104, 0.0625, 80, 0.22, 0.31, 0.0625, 0.0625, 2, 6) > > I want to take the values, for example, from a data.frame. Is it possible? > > What I mean is, if I have a table with the values: > > Variable Value > Q 22464 > T 12 > BOD 140 > ... ... > > > When I want to call the function, I indicate where to go for each value of > the variable in the table. Thus, when changing the value of the variables > in the table would be easier than doing in the function. > > Thanks!
Hi I took the liberty of simplifying things ..... # Define Your Function myfun <- function(a,b,c){ A = a + 1 B = b + 2 C = c + 3 output <- data.frame(A,B,C) return(output) } # Test The Function myfun(0,0,0) # Input Data inputData <- data.frame(a=c(1,2,3,4), b=c(10,20,30,40), c=c(100,200,300,400)) # Ouput Data outputData <- do.call(myfun, inputData) print(outputData) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/doubt-with-function-on-R-software-tp4658973p4658990.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.