[R] how to convert non numeric data into numeric?
David Winsemius
dwinsemius at comcast.net
Tue Apr 22 04:30:53 CEST 2008
"kakul modani" <kakulmodani at gmail.com> wrote in
news:91ad84370804211840y7514d720l6d119f9255c0b362 at mail.gmail.com:
> I am having the following error in my function
>
> function(theta,reqdIRR)
> {
> theta1<-theta[1]
> theta2<-theta[2]
> 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...
sum1 and sum2 are lists and "+" is expecting a vector. Two choices
--- substituting:
sum = unlist(sum1)+ unlist(sum2)
--or--
change the lapply(...) to sapply(...)
which will return a numeric vector.
--
David Winsemius
More information about the R-help
mailing list