On Wed, Apr 08, 2009 at 10:02:10AM +0200, alberto cassese wrote: > Hi, > I have problem. In the function below (test and test2) i want the function > test not to print the variable data but i want the function test2 to use the > variable test$data. > > This is the creation of the variable data: > > > matrice=c(1:10) > > matrice=matrix(matrice,nrow=5,ncol=2) > > This is the function test: > > > test=function(data){ > + return(list(x=5,data=data)) > + } > > This is the function test2: > > > test2=function(list){ > + bodri=list$data > + bodri[1,2]=bodri[2,2]+1 > + return(bodri) > + } > > Below there are the result: > > > uno=test(matrice) > > due=test2(uno) > > uno > $x > [1] 5 > > $data > [,1] [,2] > [1,] 1 6 > [2,] 2 7 > [3,] 3 8 > [4,] 4 9 > [5,] 5 10 > > > due > [,1] [,2] > [1,] 1 8 > [2,] 2 7 > [3,] 3 8 > [4,] 4 9 > [5,] 5 10 > > > What i want is: > > > uno=test(matrice) > > due=test2(uno) > > uno > $x > [1] 5
x is a variable, 5 is variable data and you don't want variable data printed? > > due > [,1] [,2] > [1,] 1 8 > [2,] 2 7 > [3,] 3 8 > [4,] 4 9 > [5,] 5 10 > Use uno[1], either directly or by creating a third variable from uno[1] > one.and.a.half <- uno[1] > one.and.a.half $x [1] 5 Or, if you *really* want what that printed output from test(matrice), create a class for your list-object, and add a special print method, that will only print the first item of the list. -- Hans Ekbrand (http://sociologi.cjb.net) <h...@sociologi.cjb.net> A. Because it breaks the logical sequence of discussion Q. Why is top posting bad?
signature.asc
Description: Digital signature
______________________________________________ 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.