# Re: [R] Fwd: how to convert non numeric data into numeric?

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Tue, 22 Apr 2008 03:46:01 +0000 (UTC)

"kakul modani" <kakulmodani_at_gmail.com> wrote in news:91ad84370804211946i4ddf7f49i5116ee7eaf5204c1_at_mail.gmail.com:

> *@ Mr. Alspach and @ Mr. Winsemius : Thanks for replying.
>
> reqdIRR contains returns in lognormal form.I am trying to estimate
> parameter for type-1 Gumbel Distribution and fit it into reqdIRR.
>
> If i use sapply its returning me NA values.

Not for me.

I think it is time to heed the posting guide. Minimal example with data and function call needed before I expend any more time in guesswork. Perhaps you called that function with a scalar for theta rather than a vector with two elements. I have no idea whether the code is correct, but it is not throwing any errors when I invoke it. -------working function -----------
> tI <- function(theta,reqdIRR)

```+ {
+ theta1<-theta
+ theta2<-theta
+ n<-length(reqdIRR)
+ constant<- n*(theta1+theta2)
+ sum1<-sapply(reqdIRR*exp (theta1),FUN = sum)
+ sum2<-sapply(exp(theta2 - reqdIRR*exp(theta1)),FUN = sum)
+ sum = sum1 + sum2
+ log.fcn = constant - as.numeric(sum)
```

# probably do not need the as.numeric
# pretty sure it already is
```+ result = - log.fcn
+ return(result)
+ }
```

>
> e.norm <- exp(rnorm(10))
> theta <- c(1,2)
> tI(theta, e.norm)

 -2.136269 -16.083672 -23.989528 -24.454704 -13.882977   -26.686971 -26.305476 -26.869672 -25.927103 -23.307188
```--
David Winsemius

> *
> I am having the following error in my function

>
> function(theta,reqdIRR)
> {
> theta1<-theta
> theta2<-theta
> n<-length(reqdIRR)
> constant<- n*(theta1+theta2)
> sum1<-lapply(reqdIRR*exp (theta1),FUN = sum)
> sum2<-lapply(exp(theta2 - reqdIRR*exp(theta1)),FUN = sum)
> sum = sum1 + sum2
> log.fcn = constant - as.numeric(sum)
> result = - log.fcn
> return(result)
> }
>
> *error :  neg.log.gumbel(1,reqdIRR)
> Error in sum1 + sum2 : non-numeric argument to binary operator
>>

>
> how can i rectify the error?Its really urgent...

>
> *
>
>      [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.
>
>

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help