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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:39:18+00:00 2026-06-06T09:39:18+00:00

Forgive me for this unbeautiful code, but I’m trying to get it to work

  • 0

Forgive me for this unbeautiful code, but I’m trying to get it to work first. (“Of course this is only temporary. Unless it works” -red green)

I’m trying to create a function that will format columns of numbers in a style that I need them. It looks like this.

    frmt <- function(x, rates=FALSE, thou=FALSE) {
  ifelse(x==0, "0", 
  ifelse(x < 0.01 & thou==TRUE, "<0.01", 
  ifelse(x < 0.1 & thou==FALSE, "<0.1", 
  ifelse(signif(x, 2) < 1 & thou==TRUE, formatC(round(x,3), format='f', digits=3),
  ifelse(signif(x, 2) < 1, formatC(round(x,2), format='f', digits=2), 
  ifelse(signif(x, 2) < 10, formatC(round(x,2), format='f', digits=1),
  ifelse(rates==FALSE, formatC(signif(x, 2), big.mark=" ", format='d'), 
  ifelse(signif(x, 3) < 100, formatC(signif(x, 2), big.mark=" ", format='d'), formatC(signif(x, 3), big.mark=" ", format='d')))))))))
}

And it works great for this:

> frmt(1413.612)
[1] "1 400"

But not this:

> frmt(c(0.0001, 0.0213, 0.25413, 1.0123, 9.9123, 15.124, 112.05, 1413.612, NA))
[1] "<0.1" "<0.1" "0.25" "1.0"  "9.9"  "0"    "0"    "0"    NA 
  • 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-06T09:39:20+00:00Added an answer on June 6, 2026 at 9:39 am

    This is the code I finally got to work

        frmt <- function(x, rates=FALSE, thou=FALSE) {
      ifelse(x==0, "0", 
      ifelse(x < 0.01 & thou==TRUE, "<0.01", 
      ifelse(x < 0.1 & thou==FALSE, "<0.1", 
      ifelse(signif(x, 2) < 1 & thou==TRUE, formatC(round(x,3), format='f', digits=3),
      ifelse(signif(x, 2) < 1, formatC(round(x,2), format='f', digits=2), 
      ifelse(signif(x, 2) < 10, formatC(round(x,2), format='f', digits=1),
      ifelse(x > 1 & rates==FALSE, formatC(signif(x, 2), big.mark=" ", format='d'), 
      ifelse(signif(x, 3) < 100, formatC(signif(x, 2), big.mark=" ", format='d'), formatC(signif(x, 3), big.mark=" ", format='d')))))))))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this is a dumb beginners problem, but I really don't get
I'm trying to get an interceptor I've written to work, but for some reason
Forgive me if this has been asked before, but I assure you I've scoured
Forgive me if this is a tried question, but I'm having a little difficulty
Forgive me for this seemingly obvious question, but my searches have not revealed the
Forgive me if this has been asked repeatedly, but I couldn't find an example
Forgive me for this noob question, but is there such a setting that sets
Forgive me if this is a particularly stupid question! mysql_query($query) returns a boolean, but
Forgive me if this is the wrong place but I am curious as to
Forgive me if this is a silly question! But to run trinidad as a

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.