[R] Function not returning a vector?
Nordlund, Dan (DSHS/RDA)
NordlDJ at dshs.wa.gov
Thu Aug 28 20:49:36 CEST 2008
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of
> rkevinburton at charter.net
> Sent: Thursday, August 28, 2008 11:36 AM
> To: r-help at r-project.org
> Subject: [R] Function not returning a vector?
>
> Why does:
>
> (shape/scale) * (1:365/scale)^(shape - 1)
>
> return a vector of numbers but calling a function
>
> hasard(1:365,shape,scale)
>
> defined like:
>
> hazard <- function(x,shape,scale)
> {
> return (shape/scale) * (x/scale)^(shape - 1)
> }
>
> Only return a single value? It is like x becomes a single
> value passed as an argument.
>
> Thank you.
>
> Kevin
>
Change your function definition to one of the following (I don't know which is "better").
hazard <- function(x,shape,scale)
{
return( (shape/scale) * (x/scale)^(shape - 1) )
}
hazard <- function(x,shape,scale)
{
(shape/scale) * (x/scale)^(shape - 1)
}
Hope this is helpful,
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
More information about the R-help
mailing list