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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:14:45+00:00 2026-06-08T00:14:45+00:00

Here is my small example: ……….. Mark <- paste (SN, 1:400, sep = )

  • 0

Here is my small example: ………..

Mark <- paste ("SN", 1:400, sep = "") 
highway <- rep(1:4, each = 100)
set.seed (1234)
MAF <- rnorm (400, 0.3, 0.1)
PPC <- abs (ceiling( rnorm (400, 5, 5)))

set.seed (1234)
Position  <- round(c(cumsum (rnorm (100, 5, 3)), 
cumsum (rnorm (100, 10, 3)), cumsum (rnorm (100, 8, 3)),
  cumsum (rnorm (100, 6, 3))), 1)

mydf <- data.frame (Mark, highway, Position, MAF, PPC)

I want to filter data which is less than 10 for PPC at the sametime greater than 0.3 for MAF.

  # filter PPC < 10 & MAF > 0.3 
 filtered <-  mydf[mydf$PPC < 10  & mydf$MAF > 0.3,]

I have grouping variable – highway and each Mark has Position on the highway. For example highway 1 for first five marks:

      1.4     7.2      15.5 13.4 19.7
 |-----|.......|.......|.....|.....|
      "SN1" "SN2"   "SN3"  "SN4" "SN5"

Now I want to pick any ~ 30 Marks such that they are well distributed in each highway based on the Position on each highway (consider different length of highway) and minimum distance between two picks is not less than 10.

Edit: The idea (rough sketch)
enter image description here

I could think a little bit on how to solve this question. Help appreciated.

Edits: Here something I could figure out:

# The maximum (length) of each highway is: 
out <-  tapply(mydf$Position, mydf$highway, max)
out 
     1      2      3      4 
 453.0 1012.4  846.4  597.6 

min(out)
[1] 453

 #Total length of all highways 
totallength <- sum(out)

# Thus average distance at which mark need to be placed:
totallength / 30 
[1] 96.98 

For highway 1, the theoritical marks could be at:

 96.98, 96.98+ 96.98, 96.98+96.98+ 96.98, ........till it is less
    than maximum (length )for highway 1.

Thus theoritically we need to choose mark at every 96.98. But the marks placed in highway may not be foud at

note: the total outcome of selection of marks need not be exactly 30 (around 30)

  • 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-08T00:14:47+00:00Added an answer on June 8, 2026 at 12:14 am

    Since we aren’t bothered about any other columns, the code is a little easier if we use split to get a list of positions.

    filtered$highway <- factor(filtered$highway)
    positions <- with(filtered, split(Position, highway))
    

    A suitable number of marks in each highway can be found using the relative length of each highway.

    highway_lengths <- sapply(positions, max)
    total_length <- sum(highway_lengths)
    n_marks_per_highway <- round(30 * highway_lengths / total_length)
    

    We can use the quantile function to get target points that are evenly spaced along each highway.

    target_mark_points <- mapply(
      function(pos, n)
      {
        quantile(pos, seq.int(0, 1, 1 / (n - 1)))
      },
      positions,
      n_marks_per_highway
    )
    

    For each target point, we find the nearest existing mark in the highway.

    actual_mark_points <- mapply(
      function(pos, target)  
      {
        sapply(target, function(tgt) 
        {
          d <- abs(tgt - pos)
          pos[which.min(d)]
        })
      },
      positions,
      target_mark_points
    )
    

    Just to see that it works, you can visualise the marks.

    is_mark_point <- mapply(
      function(pos, mark)
      {
        pos %in% mark
      },
      positions,
      actual_mark_points
    )
    
    filtered$is.mark.point <- unsplit(is_mark_point, filtered$highway)
    
    library(ggplot2)    
    (p <- ggplot(filtered, aes(Position, highway, colour = is.mark.point)) +
      geom_point()
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a small example to illustrate my data: > df <- data.frame(subgroup=rep(paste(s,1:3, sep=),
Here is small example: A <- c(1,1,1,1, 0, 0, 0, 2,2,2) B <- c(1,1,1,1,
Here is a small Example of what I would like to achieve: Maven Artifact
Here is a small example of my experience with that issue: I started to
Here's a small example (download, rename to .php and execute it in your shell):
i try to create small example to test GPS here package org.example.location; import com.google.android.maps.MapActivity;
I am trying to run a small example which i found from here http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html
Here is a small example with the masked input plugin : //apply the mask
Here I got a small example which causes the compliler to deliver a error
Here is small example I want to plot (2 group and 2 subgroup, just

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.