[R] ifelse

HBaize HBaize at buttecounty.net
Sat Oct 24 20:39:15 CEST 2009


Also, to further clarify. When you source or batch file R scripts, objects
are only printed to the screen if you use a print function. That is why the
result of the ifelse does not appear. 

Your original example would have shown the expected result of the ifelse if
it had read: 

print(ifelse ( ddd>360, ddd-360, ddd ) 

adding the print function to the ifelse in your first example, executed
using source(), will give you this output: 

[1] "numeric"
[1] 461 213 238 249 251
[1] 101 213 238 249 251
[1] 461 213 238 249 251
> 


HBaize wrote:
> 
> 
> What I think you are missing is that you didn't change ddd. The ifelse
> statement does not assign values to the ddd object. To change ddd it would
> read:
> 
> ddd <- ifelse ( ddd>360, ddd-360, ddd )
> 
> So when you enter "print(ddd)" you get the content of the original object,
> which has not changed. 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ifelse-tp26041165p26041840.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list