The following data frame represents latitude and longitude decimal coordinates. I wish to using + and – to show whether the decimal degrees are North, South, East or West (in the latitude and longitude column).
So, latitude would be positive if the decimal degrees were N.
… the latitude would be negative if the decimal degrees were S.
… the longitude would be positive if the decimal degrees were E
and the longitude would be negative if the decimal degrees were W.
a <- c(1:3)
Lat <- c(54.5, 55.2, 10.1)
NS <- c("N","N","S")
Long <- c(1.2, 0.5, 1.3)
EW <- c("W","E","W")
df1 <- data.frame(a,Lat,NS,Long,EW)
How would I do this in R? Any advice would be much appreciated.
Use
ifelse:I use
within()to reduce the amount of typing.