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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:57:31+00:00 2026-06-14T23:57:31+00:00

How can I create a vector S , with S[i] = 1, if Tv[i]

  • 0

How can I create a vector S, with

S[i] = 1, if Tv[i] is the closest number to an integer in I<- 6:10
S[i] = 0 else

Tv <- c(5.946, 5.978, 
6.01, 6.043, 6.075, 6.109, 6.14, 6.173, 6.205, 6.239, 
6.273, 6.309, 6.344, 6.379, 6.415, 6.45, 6.486, 6.521, 6.556, 
6.59, 6.627, 6.665, 6.703, 6.741, 6.778, 6.816, 6.852, 6.891, 
6.928, 6.967, 7.005, 7.045, 7.084, 7.124, 7.161, 7.202, 7.24)

S <- getS(Tv)

> dput(S) 
c(0, 0, 1, 0, 0 ....)

Final goal is to have a list like a ruler with 1 where the value is closest to the next integer value.

  • 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-14T23:57:33+00:00Added an answer on June 14, 2026 at 11:57 pm

    Here is one way:

    I <- 6:10
    S <- numeric(length(T))
    S[sapply(I, function(i) which.min(abs(i - T)))] <- 1
    S
    [1] 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I create a vector v3 = [1,100,2,99,3,98,...,100,1] using just colon notation? I've only
how can i create an istream from a buffer unsigned char* or vector. basically
How can I create and manipulate a vector of ifstreams? Something like this, except
I need to create a vector that can contain my parent class and sub
Suppose a vector with values [0,1,2,3,4,5,6,7,8,9]. How can I create a vector that refers
In the mathematical languages, you can create a vector as follows: x = seq(0,
Possible Duplicate: How can I create cartesian product of vector of vectors? I'm having
Given a std::vector which holds objects of MyClass. How can I create another vector
Question Synopsis Given a std::vector<T> , how can I create a view that exposes
Can I create an std::vector using my pre-existing data instead of it allocating new

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.