[R] Help on a simple function.

M.Kondrin mkondrin at hppi.troitsk.ru
Fri Feb 21 19:49:10 CET 2003


Ronaldo Reis Jr. wrote:
> Hi,
> 
> I try to make a function that have two others functions inside.
> 
> It is simple, but the problem is that functions inside use the same variable, 
> but with different values. I try something like this:
> 
> Teste <- function(Pdig(nlinhas),Ldig(nlinhas)) {
> 
> Pdig <- function(nlinhas) {
> Tdig <- (15.50 + 7.45*nlinhas);
> (3*(Tdig*(30/3600))+1*(30*(30/3600)));
> }
> 
> Ldig <- function(nlinhas) {
> Tdig <- (30.50 + 7.45*nlinhas);
> (2*(Tdig*(30/3600))+1*(30*(30/3600)));
> }
> 
> print(Pdig)
> print(Ldig)
> print(Pdig+Ldig)
> }
> 
> It dont work.
> 
> How to make this?
> 
> Thanks
> Ronaldo
> 

Teste <- function(nlinhas) {

Pdig <- function(z) {
Tdig <- (15.50 + 7.45*z);
(3*(Tdig*(30/3600))+1*(30*(30/3600)));
}

Ldig <- function(z) {
Tdig <- (30.50 + 7.45*z);
(2*(Tdig*(30/3600))+1*(30*(30/3600)));
}

print(Pdig(nlinhas))
print(Ldig(nlinhas))
print(Pdig(nlinhas)+Ldig(nlinhas))
}

 > Teste(10)
[1] 2.5
[1] 2
[1] 4.5
 >




More information about the R-help mailing list