Dear all, I would like to know how could I execute a sequence or orders with just a function, i.e, that just typing the function name, R gives me all the parameters I want (for instance, if I want to see the summary, the standard deviation, the number of valid cases, etc of a dataframe just with one function). I have tried with the following, but just compute the second argument of the body, i.e., the summary: resumen<-function(x) { apply(x,2,sd,na.rm=TRUE) summary(x) } Thank you very much for your help!! Manuel [[alternative HTML version deleted]]
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of Manuel Jes?s L?pez Rodr?guez > Sent: Sunday, November 29, 2009 12:17 PM > To: r-help at r-project.org > Subject: [R] sequence of commands in R > > Dear all, > I would like to know how could I execute a sequence or orders with just a > function, i.e, that just typing the function name, R gives me all the > parameters I want (for instance, if I want to see the summary, the > standard deviation, the number of valid cases, etc of a dataframe just > with one function). I have tried with the following, but just compute the > second argument of the body, i.e., the summary: > > resumen<-function(x) { > apply(x,2,sd,na.rm=TRUE) > summary(x) > } > > Thank you very much for your help!! > > Manuel >Manuel, You will need to print the results you want, or return all your results as a list. Something like: resumen<-function(x) { print(apply(x,2,sd,na.rm=TRUE)) print(summary(x)) } Or resumen<-function(x) { return(list(apply(x,2,sd,na.rm=TRUE), summary(x))) } Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA
You don't see the standard deviations because only the final result (the output of summary() in your case) is output by the function, not the intermediate results (the results of the apply() function in your case). Try this: resumen<-function(x) { print( apply(x,2,sd,na.rm=TRUE)) summary(x) } -Don At 9:17 PM +0100 11/29/09, Manuel Jes?s L?pez Rodr?guez wrote:>Dear all, >I would like to know how could I execute a >sequence or orders with just a function, i.e, >that just typing the function name, R gives me >all the parameters I want (for instance, if I >want to see the summary, the standard deviation, >the number of valid cases, etc of a dataframe >just with one function). I have tried with the >following, but just compute the second argument >of the body, i.e., the summary: > >resumen<-function(x) { > apply(x,2,sd,na.rm=TRUE) > summary(x) > } > >Thank you very much for your help!! > >Manuel > > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at 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.-- --------------------------------- Don MacQueen Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 macq at llnl.gov
On 11/30/2009 07:17 AM, Manuel Jes?s L?pez Rodr?guez wrote:> Dear all, > I would like to know how could I execute a sequence or orders with just a function, i.e, that just typing the function name, R gives me all the parameters I want (for instance, if I want to see the summary, the standard deviation, the number of valid cases, etc of a dataframe just with one function). I have tried with the following, but just compute the second argument of the body, i.e., the summary: > > resumen<-function(x) { > apply(x,2,sd,na.rm=TRUE) > summary(x) > } > >Hi Manuel, This looks very much like one of the "alternative summary" functions. Three, all named "describe", can be found in the Hmisc, psych and prettyR packages. Jim
Manuel Jes?s L?pez Rodr?guez wrote:> Dear all, > I would like to know how could I execute a sequence or orders with just a function, i.e, that just typing the function name, R gives me all the parameters I want (for instance, if I want to see the summary, the standard deviation, the number of valid cases, etc of a dataframe just with one function). I have tried with the following, but just compute the second argument of the body, i.e., the summary: > > resumen<-function(x) { > apply(x,2,sd,na.rm=TRUE) > summary(x) > } > > Thank you very much for your help!! > > Manuel > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >Hi Manuel, In addition to my fellow R-helpers: R does not save the result of the apply function on x. Now you calculate it and it is discarded. To save it, try something like: resumen<-function(x) { y = apply(x,2,sd,na.rm=TRUE) summary(y) } Or print statements on both lines, as the others suggested. cheers, Paul -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul