b_spread: base spread

Description Usage Arguments Value Author(s) Examples

View source: R/spread.R

Description

base spread mimics basic functionality of tidyr::spread

Usage

1
b_spread(data, key, value, convert = FALSE)

Arguments

data

data.frame

key

column which will become the new columns

value

column name which will populate new columns

convert

type.convert will run on each result column if TRUE, Default: FALSE

Value

data.frame

Author(s)

Jonathan Sidi

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
stocks <- data.frame(
time = as.Date('2009-01-01') + 0:9,
X = rnorm(10, 0, 1),
Y = rnorm(10, 0, 2),
Z = rnorm(10, 0, 4)
)
stocksm <- b_gather(stocks,'stock', 'price', -1)
b_spread(stocksm, 'stock', 'price')
# spread and gather are complements
df <- data.frame(x = c("a", "b"), y = c(3, 4), z = c(5, 6))
sdf <- b_spread(df, 'x', 'y')
b_gather(sdf, 'x', 'y', -1, na.rm = TRUE)

# Use 'convert = TRUE' to produce variables of mixed type
df <- data.frame(row = rep(c(1, 51), each = 3),
                 var = c("Sepal.Length", "Species", "Species_num"),
                 value = c(5.1, "setosa", 1, 7.0, "versicolor", 2))

str(b_spread(df, 'var', 'value'))
str(b_spread(df, 'var', 'value',convert = TRUE))

yonicd/bplyr documentation built on Feb. 24, 2020, 2 p.m.