For a university project, I have to set 4 logic conditions in order to do different operations, that is to say:
If an element from list1 (Latitude_Difference) is 0 && elements from list2 (Longitud_Difference) is 0, then operate: "element from list3 (Rumbo) = element from list3 + 180". Else evaluate the next condition
If an element from list1 is 0 && elements from list2 is > 0, then operate: " element from list3 = element from list3 -180". Else evaluate the next condition
If an element from list1 is > 0 && element from list2 is 0, then operate: element from list3 = 360 - element from list3". Else evaluate the next condition
If an element from list1 is > 0 && element from list2 is > 0, then operate: "element from list3 = element from list3". Else start again from the beginning
I attach a short reprex to illustrate my problem:
library(ggplot2)
data.frame(
Longitud_Difference = c(0.355555555555554, 2.03333333333333,
-2.98833333333334, -0.122222222222222,
-0.483055555555556, -0.0458333333333333, 0.218611111111111)
)
#> Longitud_Difference
#> 1 0.35555556
#> 2 2.03333333
#> 3 -2.98833333
#> 4 -0.12222222
#> 5 -0.48305556
#> 6 -0.04583333
#> 7 0.21861111
data.frame(
Latitude_Difference = c(0.161666666666669, -1.57138888888889,
1.99666666666667, 0.0402777777777743,
0.172222222222224, 0.0633333333333326, -0.144999999999996)
)
#> Latitude_Difference
#> 1 0.16166667
#> 2 -1.57138889
#> 3 1.99666667
#> 4 0.04027778
#> 5 0.17222222
#> 6 0.06333333
#> 7 -0.14500000
data.frame(
Rumbo = c(52.6522407924064, 52.1141691114194, 55.9611717385204,
62.9774520248583, 61.3077347299283, 24.8865879986665,
43.2327065129182)
)
#> Rumbo
#> 1 52.65224
#> 2 52.11417
#> 3 55.96117
#> 4 62.97745
#> 5 61.30773
#> 6 24.88659
#> 7 43.23271
Rumbo <- function(RumboAbs,Longitud_Difference,Latitude_Difference){
declon = if_else(
condition = (Longitud_Difference<0 && Latitude_Difference<0),
true = (RumboAbs = 180+RumboAbs),
false = RumboAbs,
condition = (Longitud_Difference<0 && Latitude_Difference>0),
true = (360-RumboAbs),
false = RumboAbs,
condition = (Longitud_Difference>0 && Latitude_Difference>0),
true = (RumboAbs),
false = RumboAbs,
condition = (Longitud_Difference>0 && Latitude_Difference<0),
true = (180-RumboAbs),
false = RumboAbs
)
return(declon)}
RumboCircular<-
mutate(RumboCir = Rumbo(RumboAbs,Diferencia_Latitud,Diferencia_Longitud))
#Error in if_else(condition = (Longitud_Difference < 0 && Latitude_Difference < :
#formal argument "condition" matched by multiple actual arguments
reprex::reprex()