Description Usage Arguments Details Value See Also Examples
#' @description This is now deprecated and no longer needed due to advancements in 'tidyr'.
1 2 3 4 5 6 7 8 9 10 |
data |
See |
key |
See |
value |
See |
compact |
When you don't have a unique identifier there is more than one way the output could be produced. Actually two. One is rather messy but may in fact be what is desired. The other is more 'compact'. See the examples. |
fill |
See |
convert |
See |
drop |
See |
sep |
See |
Anyone that uses spread more than once has likely come across the
duplicate identifiers problem. This function works just like select (it's
mostly just a wrapper) except that it works when you don't have unique
identifiers, which is actually quite often. The only additional
functionality regards the compact
argument. See the examples for
what this means.
For more, see StackOverflow for example, or the numerous repeated issue brought up at the tidyr GitHub issues page. Search for 'spread duplicate' for all, not just open issues (direct link couldn't be handled by R documentation).
A data frame with 'wide' format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ## Not run:
library(tidyext); library(tidyr)
# initial example from spread
stocks_init <- 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)
)
# a very common situation
stocks <- data.frame(
X = rnorm(10, 0, 1),
Y = rnorm(10, 0, 2),
Z = rnorm(10, 0, 4)
)
stocksm_init <- stocks_init %>% gather(stock, price, -time)
stocksm_init %>% spread(stock, price) # works fine
stocksm <- stocks %>% gather(stock, price)
# stocksm %>% spread(stock, price) # annoying
stocksm %>% spread2(stock, price) # works fine
stocksm %>% spread2(stock, price, compact = FALSE)
# works with NA
stocksm$price[sample(1:nrow(stocksm), 5)] = NA
stocksm %>% spread2(stock, price)
stocksm %>% spread2(stock, price, compact = FALSE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.