pking wrote:
When I run this code from an R-script:
       ddd = 360 + round ( atan2(-u,-v) / d2r )
       print(class(ddd))
       print(ddd)
       ifelse ( ddd>360, ddd-360, ddd )
       print(ddd)
I get this output: [1] "numeric"
[1] 461 213 238 249 251
[1] 461 213 238 249 251

Why does ifelse not change the 461 to 101?


Because you never changed ddd

You want the last but one line to be

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

I guess.



I recreated the vector ddd and ran the same ifelse
code and it did work as expected.
ddd <- c(461, 213, 238, 249, 251) print(class(ddd))
[1] "numeric"

print(ddd)
[1] 461 213 238 249 251

ifelse ( ddd>360, ddd-360, ddd )
print(ddd)
[1] 101 213 238 249 251


I doubt.


What am I missing?

That you made an assignment

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

that you have not told us (nor youself?) in your second case.

Best,
Uwe Ligges


Patrick King



______________________________________________
R-help@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.

Reply via email to