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

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Tue, 22 Apr 2008 02:30:53 +0000 (UTC)

"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

--or--
change the lapply(...) to sapply(...)

which will return a numeric vector.

-- 
David Winsemius

______________________________________________
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.
Received on Tue 22 Apr 2008 - 02:35:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Apr 2008 - 03:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive