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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:23:00+00:00 2026-06-02T19:23:00+00:00

I have the following example data frame in R. item index ptr A 1

  • 0

I have the following example data frame in R.

  item index  ptr
     A     1 0.40
     B     2   NA
     C     3 0.30
     D     4 0.35
     E     5 0.44
     F     6   NA

It is already sorted based on column = index. Now, I would like to sort it by the column ptr but by leaving the position of rows where ptr = NA intact. So the output I’m expecting is:

  item index  ptr
     C     3 0.30
     B     2   NA
     D     4 0.35
     A     1 0.40
     E     5 0.44
     F     6   NA

The regular df = df[order(ptr),] doesn’t work. Any ideas? Thanks much 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-06-02T19:23:01+00:00Added an answer on June 2, 2026 at 7:23 pm

    try this:

    > df
      item index  ptr
    1    A     1 0.40
    2    B     2   NA
    3    C     3 0.30
    4    D     4 0.35
    5    E     5 0.44
    6    F     6   NA
    > df[!is.na(df$ptr), ] <- df[order(df$ptr, na.last = NA), ]
    > df
      item index  ptr
    1    C     3 0.30
    2    B     2   NA
    3    D     4 0.35
    4    A     1 0.40
    5    E     5 0.44
    6    F     6   NA
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data file that looks like the following example. I've added '%'
I have a large data frame with the following fields (example data). #dput(data) gives...
I have the following question: I have data frame which looks like this. I
I have following structure with example data: id season_id title 1 1 Intro 2
In the following example I have two years worth of data denoted by data_2007
As a simplified example, I have the following data classes: public class Employee {
i have the following data frame dd <- data.frame(b = c(High, Medium, Highest, Low,
I have the following data frame: > str(df) 'data.frame': 3149 obs. of 9 variables:
I have the following problem in R: Lets assume the following data frame: a
I have a data frame, such as the following: name day wages 1 Ann

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.