[R] sequence of commands in R
Daniel Nordlund
djnordlund at verizon.net
Mon Nov 30 01:01:24 CET 2009
> -----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
More information about the R-help
mailing list