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 6990975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:25:48+00:00 2026-05-27T19:25:48+00:00

I have a dataframe df with three variable: city , state and country .

  • 0

I have a dataframe df with three variable: city, state and country. I want to calculate 3 things

  1. Calculate the latitude/longitude for each row.
  2. Calculate the distance of each city from an arbitrary point, say country capital
  3. Calculate the elevation of each point from the lat/long.

I can use the dismo package for 1, but can’t figure out a way to “bulk process” from df, instead of copying and pasting the city, state and country names directly into the geocode(c()) code. As for 2 and 3, I am stumped completely. Any help would be appreciated.

EDIT NOTE: To other readers of this post… I appreciate the help from both Paul and Spacedman. The system won’t allow me to mark more than one response as correct. I gave Paul the thumbs up because he responded before Spaceman. Please read what both of them have taken the time to write up. Thanks.

  • 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-05-27T19:25:49+00:00Added an answer on May 27, 2026 at 7:25 pm

    I’ll share my thoughts on each of the points:

    For 1. you can use paste to create an input vector for geocode:

    df$geocode_string = with(df, paste(city, state, country, sep = ", "))
    coords_latlong = geocode(df$geocode_string)
    

    In regard to point number 2, after converting df to one the classes provided by the sp package (SpatialPointsDataFrame, look at the coordinates function from sp), you can use spDistsN1 to find the distance of all the points to one other point.

    The final is a bit more tricky, to find the height you need a DEM (digital elevation model). Maybe there is a more easy way along the lines of geocode which I am not aware of.

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

Sidebar

Related Questions

I have a dataframe in R with three variables named for example df$V1 ,
I have a dataframe with columns labeled A,B & C. I want to add
I have a dataframe with three variables: ID , group , and nominated_ID .
Suppose I have a response variable and a data containing three covariates (as a
I have a dataframe, and I want to produce a table of summary statistics
I have a dataframe df. I want to create two subsets (a & b)
I have a dataframe with numeric entries like this one test <- data.frame(x =
I have a dataframe with a column of integers that I would like to
Suppose I have a dataframe like this one: df <- data.frame (id = c(a,
(second question today - must be a bad day) I have a dataframe with

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.