I have a very large table (n=2,723,860
) and I want to calculate positive wind direction (0 to 360 degrees) from negative wind direction (-180 to 180 degrees).
One of my loops, a for loop with a nested if and else if statement, takes forever to run (see below).
I am new to R and I am thinking that I just don't have this structured efficiently. Any help on how to better structure this so that it doesn't take so long (currently at 20 minutes and it still isn't done)?
for (j in 1:n){
if (Jun012015$D[j] < 0){
Jun012015$D1[j] <- (Jun012015$D[j] * (-1))
} else if (Jun012015$D[j] > 0){
Jun012015$D1[j] <- ((Jun012015$D[j] * (-1)) + 360)
} else {
Jun012015$D1[j] <- 0
}
}