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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:07:21+00:00 2026-05-31T11:07:21+00:00

I got a file containing the following data: str(dat) List of 2 $ x:

  • 0

I got a file containing the following data:

str(dat)
List of 2
 $ x: Named num [1:28643] 2714769 2728569 NA 2728569 2740425 ...
  ..- attr(*, "names")= chr [1:28643] "h" "h" "" "h" ...
 $ y: Named num [1:28643] 925000 925000 NA 925000 925000 ...
  ..- attr(*, "names")= chr [1:28643] "h" "h" "" "h" ...
 - attr(*, "class")= chr [1:2] "bor" "list"

dat$x[1:10]
      h       h               h       h               h       h               h 
2714769 2728569      NA 2728569 2740425      NA 2740425 2751585      NA 2751585 

dat$y[1:10]
      h      h             h      h             h      h             h 
 925000 925000     NA 925000 925000     NA 925000 925000     NA 925000 

class(dat)
"bor"  "list"

table(names(dat$x))
          h 
  479 28164 

table(names(dat$y))
          h 
  479 28164 

plot(dat, type=’l’) results in a nice map.

I read about an old/simple form of line-‘objects’ used in S in “Applied Spatial Data Analysis with R” (Bivand, Pebesma, Gomez-Rubio; Springer 2008) on Page 38, which seem to have similarities to my file. This format defines a line as “start-point; end-point; NA” triplet.

Do you know this format?
How can I convert it to an sp-object?

Thanks in advance

  • 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-31T11:07:23+00:00Added an answer on May 31, 2026 at 11:07 am

    Based on your information, here is one possilbe way to go:

    Assuming that your data represent lines and that the NA values indicate the end of each line, you can convert your data to spatial lines doing the following:

    # Creating artificial data for the example
    dat <- list()
    dat$x <- rnorm(1000) + rep(c(rep(0, 99), NA), 10)
    dat$y <- dat$x + rnorm(1000)
    
    # For simplicity, convert to data frame
    # (this would be the first step for you to do with your data)
    mydat <- data.frame(x = dat$x, y = dat$y)
    
    # Convert each part to a line, using the NA values as breaks
    mylines <- list()
    last <- 1
    for(i in 1:nrow(mydat)){
        if(is.na(mydat$x[i])){
            print(i)
            mylines[[as.character(i)]] <- Lines(Line(mydat[last:(i-1),]), ID = as.character(i))
            last <- i+1
        }
    }
    
    # Convert to spatial lines object
    mylines <- SpatialLines(mylines)
    
    # Plot to see if it worked
    plot(mylines)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iv'e got an xml file containing data about games, which are an .exe download;
I've got a file containing several channels of data. The file is sampled at
I've got an excel file containing a list of records by firstname, lastname, email_address,
I've got around 10 lines of data in a text file below containing the
Let's say you got a file containing texts (from 1 to N) separated by
I've got a CSV file containing latitude and longitude values, such as: 25°36'55.57E,45°39'12.52N Anyone
Hi I've got a log file containing trace routes and pings. Ive seperated these
this is probably pretty simple, but I've got this text file containing a bunch
I've got a ZIP file containing a number of PNG images that I am
I have got a file containing a large amount of numbers. I have tried

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.