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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:17:54+00:00 2026-06-15T00:17:54+00:00

I came to R from SAS, where numeric missing is set to infinity. So

  • 0

I came to R from SAS, where numeric missing is set to infinity. So we can just say:

positiveA = A > 0;

In R, I have to be verbose like:

positiveA <- ifelse(is.na(A),0, ifelse(A > 0, 1, 0))

I find this syntax is hard to read. Is there anyway I can modify ifelse function to consider NA a special value that is always false for all comparison conditions? If not, considering NA as -Inf will work too.

Similarly, setting NA to ” (blank) in ifelse statement for character variables.

Thanks.

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

    This syntax is easier to read:

    x <- c(NA, 1, 0, -1)
    
    (x > 0) & (!is.na(x)) 
    # [1] FALSE  TRUE FALSE FALSE
    

    (The outer parentheses aren’t necessary, but will make the statement easier to read for almost anyone other than the machine.)


    Edit:

    ## If you want 0s and 1s
    ((x > 0) & (!is.na(x))) * 1
    # [1] 0 1 0 0
    

    Finally, you can make the whole thing into a function:

    isPos <- function(x) {
        (x > 0) & (!is.na(x)) * 1
    }
    
    isPos(x)
    # [1] 0 1 0 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have came from another question to this one: How can one start with
I have a JSON encoded array that looks like this (it came from a
User can came from web or from devise (Android|iPhone|iPad|iPod) How correctly detect it?
I have a record that came from the follow linq query: using (var context
I have a form with a hidden Came from Adwords field that will be
I have MS Visual Studio web project folder came from TFS server with several
I came from a java background, and I was trying to use protocol like
How can I determine where a user came from when they land on my
I have merge two array with php function merge_recursive (both came from sql query)
I have a data that came from a session and I want to parse

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.