[R] R-way to doing this?

Bogaso Christofer bogaso.christofer at gmail.com
Thu Dec 23 19:30:24 CET 2010


Thanks Patrick for you input. That is what I wanted. I must have read the
R-Inferno long time back.........................

-----Original Message-----
From: Patrick Burns [mailto:pburns at pburns.seanet.com] 
Sent: 23 December 2010 15:01
To: r-help at r-project.org; bogaso.christofer
Subject: Re: [R] R-way to doing this?

If I understand your question
properly, then you are looking
for 'try' or 'tryCatch'.  There
is an example of using these on
page 89 of 'The R Inferno'.

On 23/12/2010 04:13, Bogaso Christofer wrote:
> Dear friends, hope I could be able to explain my problem through 
> following example. Please consider this:
>
>
>
>> set.seed(1)
>
>> input<- rnorm(10)
>
>> input
>
> [1] -0.6264538  0.1836433 -0.8356286  1.5952808  0.3295078 -0.8204684
> 0.4874291  0.7383247  0.5757814 -0.3053884
>
>> tag<- vector(length=10)
>
>
>
> for(i in 1:10)
>
>      #  if there is any ****error**** in evaluating "log(input[i])" 
> (or evaluating some function) then tag[i] = 1, otherwise tag[i] = 0
>
>
>
> Therefore my "tag" vector should like: tag[1]=1, tag[2]=0, tag[3]=1, 
> tag[4]=0, tag[5]=0.......
>
>
>
> Actually R returns logarithm of a negative number as NaN, however in 
> this example please consider R returns error when it encounters 
> logarithm of a negative number.
>
>
>
> Is there any way to do above task?
>
>
>
> Thanks and regards,
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

--
Patrick Burns
pburns at pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')



More information about the R-help mailing list