MyNixOS website logo
Description

Fill Missing Values in Vectors.

Edit vectors to fill missing values, based on the vector itself.

fillr

Travis buildstatus Codecov testcoverage

Fillr is an R package. The goal of fillr is to edit vectors to fill missing values, based on the vector itself. These functions are best used on variables within a grouped data frame.

Installation

Fillr is on CRAN, you can install the stable release using

# Install release version from CRAN
intall.packages("fillr")

# Install development version from GitHub
devtools::install_github("jelger12/fillr")

Example

When you want to fill values in a vector with another value, the fillr functions can be used to impute all NA values based on some set rules.

Fill the NA values with the minimum, maximum or last value

fill_missing_min(c(1, 2, 1, 1, NA))
#> [1] 1 2 1 1 1
fill_missing_max(c(1, 2, 1, 1, NA))
#> [1] 1 2 1 1 2
fill_missing_last(c(1, NA, 1, 2, NA))
#> [1] 1 2 1 2 2

Fill the NA values with the same value, only when all non-NA values are the same

fill_missing_strict(c(1, NA, 1, 1, NA))
#> [1] 1 1 1 1 1
fill_missing_strict(c("a", NA, "a", "a", NA))
#> [1] "a" "a" "a" "a" "a"

Fill the NA values with the previous value (repeating with multiple repeating NA values)

fill_missing_previous(c(1, NA, 1, 2, NA, NA))
#> [1] 1 1 1 2 2 2

Fill missing values given the observed interval within the vector

fill_missing_interval(c(NA, NA, 2, 4, NA, NA))
#> [1] -2  0  2  4  6  8

Example within a grouped data frame

Fillr is best used within a grouped data frame. You can use the fill_missing_ functions to fill the missing values within the groups.

# Use tibble and dplyr for this example
library(tibble)
library(dplyr)
# Create a tibble with missing values
df <-tibble(group = c("a", "a", "a", "b", "b", "b"),
            value = c(NA, 1 , NA, 5, 6, NA)) 
df
#> # A tibble: 6 x 2
#>   group value
#>   <chr> <dbl>
#> 1 a        NA
#> 2 a         1
#> 3 a        NA
#> 4 b         5
#> 5 b         6
#> 6 b        NA

# Use fillr functions to fill the missing data 
df %>% 
  group_by(group) %>% 
  mutate(value_strict    = fill_missing_strict(value),
         value_min       = fill_missing_min(value),
         value_previous  = fill_missing_previous(value))
#> # A tibble: 6 x 5
#> # Groups:   group [2]
#>   group value value_strict value_min value_previous
#>   <chr> <dbl>        <dbl>     <dbl>          <dbl>
#> 1 a        NA            1         1             NA
#> 2 a         1            1         1              1
#> 3 a        NA            1         1              1
#> 4 b         5            5         5              5
#> 5 b         6            6         6              6
#> 6 b        NA           NA         5              6
Metadata

Version

1.0.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows