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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:12:47+00:00 2026-06-16T00:12:47+00:00

How can I replace the results of the findinterval function with my desired numbers?

  • 0

How can I replace the results of the findinterval function with my desired numbers? Below is the dput() output:

a=c(113,113,113,113,111,111,115,116,117,118,220,220)
b=c(113,113,113,113,111,111,115,116,117,118,220,220)
c=c(2,2,1,1,5,1,1,2,1,1,1,4)
d=c(2,2,12,12,15,12,12,2,12,12,12,14)
e=c(1,1,1,1,1,2,2,2,2,2,2,3)
f=c(20,30,25,35,45,55,60,65,70,75,75,80)
h=c("1A","1A","2A","3A","1A","5A","4A","4A","7A","7A","9A","9A")
i=c(12,16,17,19,20,15,18,17,17,13,14,15)

m=data.frame(a=a,b=b,c=c,d=d,e=e,f=f,h=h,i=i)

dput(m)
structure(list(a = c(113, 113, 113, 113, 111, 111, 115, 116, 
117, 118, 220, 220), b = c(113, 113, 113, 113, 111, 111, 115, 
116, 117, 118, 220, 220), c = c(2, 2, 1, 1, 5, 1, 1, 2, 1, 1, 
1, 4), d = c(2, 2, 12, 12, 15, 12, 12, 2, 12, 12, 12, 14), e = c(1, 
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3), f = c(20, 30, 25, 35, 45, 55, 
60, 65, 70, 75, 75, 80), h = structure(c(1L, 1L, 2L, 3L, 1L, 
5L, 4L, 4L, 6L, 6L, 7L, 7L), .Label = c("1A", "2A", "3A", "4A", 
"5A", "7A", "9A"), class = "factor"), i = c(12, 16, 17, 19, 20, 
15, 18, 17, 17, 13, 14, 15)), .Names = c("a", "b", "c", "d", 
"e", "f", "h", "i"), row.names = c(NA, -12L), class = "data.frame")

set.seed(5)
m$rand <- runif(nrow(m))

m[a==113,"i"] <- c(10,11,12)[1+findInterval(unlist(m[m$a==113,"rand",with=F]),c(0.25,0.50))]

Is there any easy way to draw from a values vector which has all these correspondences in one place. For instance have [for a==113 c(0.25,0.50),values=c(10,11,12)] [for a==111 c(0.25,0.50,0.75),values=c(1,2,3,4)] [for a==115 c(0.25,0.50,0.75),values=c(1,2,3,4)] all in one table or frame and draw from these whenever the findinterval function is used? The i column is supposed to be replaced by values wherever related. What I want to do is to read the values (e.g. c(10,11,12)) from another file and put in the findinterval function whenever needed.

  • 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-16T00:12:48+00:00Added an answer on June 16, 2026 at 12:12 am

    The 0 and 1 are what is being returned by findInterval. That result should be used to index the values you are interested in. Try:

    > k[a==113,"WWW"] <- c(10,11)[1+findInterval(unlist(k[k$a==113,"rand",with=F]),c(0.45))]
     # or draw from the values vector based on your comment 
    # (which should instead be an edit rather than a comment.
    values=c(10,11,12)
    k[a==113,"WWW"] <- values[1+findInterval(unlist(k[k$a==113,"rand",with=F]),c(0.45))]
    > k
         a b  c d  e WWW      rand
    1: 113 2  2 1 20  10 0.2002145
    2: 113 2  2 1 30  11 0.6852186
    3: 112 1 12 1 25  17 0.9168758
    4: 114 1 12 1 35  19 0.2843995
    

    Since vectors are 1 based rather than zero based you need to add the 1 to the result.

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

Sidebar

Related Questions

How can replace values as array by replace in javascript. I want done replace
How can replace arabic number with latin number as that doesn't change number into
How i can replace any character except 0-9 a-z and and array of some
so 1GvG:s/..../g can replace over an entire buffer However, suppose I have multiple vim
How i can replace some characters when user type a sentence in EditText? For
I need to know how I can replace the last s from a string
I was wondering if there is any way that I can replace substrings within
Can I replace the maxlength attribute with something in CSS? <input type='text' id=phone_extension maxlength=4
How can I replace caracters on the fly when using sed ? Example :
I'm trying to pass the results array generated by sqlite3_get_table contained in a function

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.