Giter Site home page Giter Site logo

lucid's Introduction

lucid

CRAN_Status_Badge CRAN_Downloads

Homepage: https://kwstat.github.io/lucid

Repository: https://github.com/kwstat/lucid

The 'lucid' package provides a simple function to improve the format of floating-point numbers for humans. The 'lucid()' function is primarily a formatting function similar to 'round' and 'signif', but output is always character.

Note: The lucid package was created before the tibble package. The tibble package now uses a similar style of formatting dataframes.

Key features

  • Simple to use.

  • Makes floating-point numbers easier to read.

Installation

# Install the released version from CRAN:
install.packages("lucid")

# Install the development version from GitHub:
install.packages("devtools")
devtools::install_github("kwstat/lucid")

Usage

In the short example below, a separate regression line is fit to each of five trees' circumference versus age. The default output is difficult to interpret quickly. The lucid function makes the results much cleaner by reducing visual clutter and aligning decimals.

require(lucid)
require(dplyr)
require(broom)

# Fit a separate regression line to each tree. 
# Use `as.data.frame` to remove formatting done by `tibble`.
Orange %>% group_by(Tree) %>% do(tidy(lm(circumference ~ age, data=.))) %>% as.data.frame

Source: local data frame [10 x 6]
Groups: Tree [5]

    Tree        term    estimate    std.error statistic      p.value
   <ord>       <chr>       <dbl>        <dbl>     <dbl>        <dbl>
1      3 (Intercept) 19.20353638  5.863410215  3.275148 2.207255e-02
2      3         age  0.08111158  0.005628105 14.411881 2.901046e-05
3      1 (Intercept) 24.43784664  6.543311039  3.734783 1.350409e-02
4      1         age  0.08147716  0.006280721 12.972581 4.851902e-05
5      5 (Intercept)  8.75834459  8.176436207  1.071169 3.330518e-01
6      5         age  0.11102891  0.007848307 14.146861 3.177093e-05
7      2 (Intercept) 19.96090337  9.352361105  2.134317 8.593318e-02
8      2         age  0.12506176  0.008977041 13.931291 3.425041e-05
9      4 (Intercept) 14.63762022 11.233762751  1.303002 2.493507e-01
10     4         age  0.13517222  0.010782940 12.535748 5.733090e-05

# Now extend the pipe to include 'lucid'
Orange %>% group_by(Tree) %>% do(tidy(lm(circumference ~ age, data=.))) %>% as.data.frame %>% lucid

# Note: `tibble` now uses formatting almost identical to `lucid`
# Orange %>% group_by(Tree) %>% do(tidy(lm(circumference ~ age, data=.)))

Source: local data frame [10 x 6]
Groups: Tree [5]

    Tree        term estimate std.error statistic   p.value
   <ord>       <chr>    <chr>     <chr>     <chr>     <chr>
1      3 (Intercept)  19.2      5.86         3.28 0.0221   
2      3         age   0.0811   0.00563     14.4  0.0000290 
3      1 (Intercept)  24.4      6.54         3.73 0.0135   
4      1         age   0.0815   0.00628     13    0.0000485
5      5 (Intercept)   8.76     8.18         1.07 0.333    
6      5         age   0.111    0.00785     14.1  0.0000318
7      2 (Intercept)  20        9.35         2.13 0.0859   
8      2         age   0.125    0.00898     13.9  0.0000343
9      4 (Intercept)  14.6     11.2          1.3  0.249    
10     4         age   0.135    0.0108      12.5  0.0000573

lucid's People

Contributors

kwstat avatar

Stargazers

Shayne Qian avatar Krzysztof Joachimiak avatar Diogo Melo avatar Gumeo avatar Romain François avatar Christophe Dervieux avatar Duncan Garmonsway avatar Eduard Szöcs avatar  avatar David Barron avatar Dave Braze avatar Neal Fultz avatar Travis Taylor avatar Joshua Kunst avatar Andrew Heiss avatar Thomas J. Leeper avatar TJ Mahr avatar Maëlle Salmon avatar Nicholas Tierney avatar Adam H. Sparks avatar Ben Marwick avatar Nate Teetor avatar Kyaw Sint avatar Kirill Müller avatar

Watchers

 avatar James Cloos avatar Ross Gayler avatar  avatar Shayne Qian avatar

Forkers

johnomeara

lucid's Issues

FR: Color output

Instead of discarding insignificant digits, they could be shown in pale gray. In cases like 1.2473 and 3 digits, perhaps the 7 can be displayed in a darker gray.

For tidyverse/tibble#30. The crayon package could take care of coloring the output.

NA values

It would be quite useful to be able to replace NA values with something (e.g., blank space) after the formatting stage. Something along the lines of:

lucid(X, na.replace=" ")

defaulting to

lucid(X, na.replace=NULL)

where is.null(na.replace) indicates no replacement. Perhaps nested [ls]apply and gsub?

data.frame(apply(X, 2, function(x) apply(matrix(x), 1, function(y) gsub('NA', "--", y))))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.