Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:13:05+00:00 2026-06-17T15:13:05+00:00

The following data frame represents latitude and longitude decimal coordinates. I wish to using

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:13:06+00:00Added an answer on June 17, 2026 at 3:13 pm

    Use ifelse:

    df1 <- within(df1, {
                 Lat <- ifelse(NS=="N", Lat, -Lat)
                 Long <- ifelse(EW=="E", Long, -Long)
    })
    
    df1
      a   Lat NS Long EW
    1 1  54.5  N -1.2  W
    2 2  55.2  N  0.5  E
    3 3 -10.1  S -1.3  W
    

    I use within() to reduce the amount of typing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to access $a using the following example: df<-data.frame(a=c(x,x,y,y),b=c(1,2,3,4)) > df a b
Using ggplot2 generate a plot which shows the following data. df=data.frame(score=c(4,2,3,5,7,6,5,6,4,2,3,5,4,8), age=c(18,18,23,50,19,39,19,23,22,22,40,35,22,16)) str(df) df
I ran into a little problem using R… In the following data frame test
Suppose I have the following data frame: Data1 X1 X2 1 15 1 2
I have the following data test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10)) I would like a barplot with
I have the following data.frames: a <- data.frame(id = 1:3, v1 = c('a', NA,
How can I subset the following example data frame to only return one observation
I have the following data: a=c(1:10) b=c(16:25) c=c(24:33) wa=c(3,7,3,3,3,3,3,3,3,1) wb=c(3,2,3,3,3,3,3,3,3,8) wc=c(4,1,4,4,4,4,4,4,4,1) z=data.frame(a,b,c,wa,wb,wc) I want
I have the following dataframe: DF <- data.frame(x = c(1, 2, 3,NA), y =
I have the following dummy code: dt<-data.frame(country=letters[1:20],val=rnorm(20),siz=rnorm(20)) qplot(x=country,y=val,data=dt,geom=point,size=siz) Now I want to increase the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.