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

  • Home
  • SEARCH
  • 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 8306401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:19:28+00:00 2026-06-08T18:19:28+00:00

I have a data frame with distances between start and end points. Start points

  • 0

I have a data frame with distances between start and end points. Start points are in rows, end points are in columns. Now I want to have them printed each one by one (startpoint endpoint distance newline). Missing values (NAs) should be omitted.

This is my data frame:

          EndPoint
    StartPoint TX001    TX002    TX003
         TX002  37.4       NA       NA
         TX003    NA 14.78704       NA
         TX005    NA       NA 60.78947

What I want to get is:

    TX002 TX001 37.4
    TX003 TX002 14.78704
    TX005 TX003 60.78947

Any help is greatly appreciated.

Sugi

  • 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-08T18:19:30+00:00Added an answer on June 8, 2026 at 6:19 pm

    If I’ve missed the mark, please use dput to provide a sample of your data. However, assuming your data looks like this:

    dat <- structure(list(StartPoint = c("TX002", "TX003", "TX005"), TX001 = c(37.4, 
    NA, NA), TX002 = c(NA, 14.78704, NA), TX003 = c(NA, NA, 60.78947
    )), .Names = c("StartPoint", "TX001", "TX002", "TX003"), class = "data.frame", row.names = c(NA, 
    -3L))
    

    You can use melt from the reshape2 package and then drop the extra rows with na.omit.

    > na.omit(melt(dat, 
                   id.var='StartPoint', 
                   variable.name='EndPoint', 
                   value.name='Distance'))
    
      StartPoint EndPoint Distance
    1      TX002    TX001 37.40000
    5      TX003    TX002 14.78704
    9      TX005    TX003 60.78947
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame with start dates and end dates, along with the
I have a data frame like below (20,000 rows by 49 cols). Each row
I have a data frame that is some 35,000 rows, by 7 columns. it
I have a data frame with 22239 rows & 200 columns. The first column
I have data frame with two column say a and b now I want
I have a dataframe with distances df<-data.frame(site.x=c(A,A,A,B,B,C), site.y=c(B,C,D,C,D,D),Distance=c(67,57,64,60,67,60)) I need to convert this to
I have a data frame of daily data: df with four columns: Date, A,
I have a data.frame , called so_data. Columns 13:23 are list s, which hold
I have data.frame that contains several factors and i want to rename factor levels
I have a data frame with 30 columns numbered from 0 to 29. I

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.