I have some long data, that I could like to widen. My initial data Looks lLike this
df <- read.table(text = 'Item Amount
1000 10
1000 1
1500 5
1500 2',
header = TRUE)
library(tidyverse)
Now, I would like to widen it, using tidyr's pivot_wider()
,
df %>%
tidyr::pivot_wider(names_from = Item, values_from = Amount)
# A tibble: 1 x 2
`1000` `1500`
<list> <list>
1 <int [2]> <int [2]>
Warning message:
Values are not uniquely identified; output will contain list-cols.
* Use `values_fn = list` to suppress this warning.
* Use `values_fn = length` to identify where the duplicates arise
* Use `values_fn = {summary_fun}` to summarise duplicates
but I get some error I cannot resolve. What I expected was this, what am I doing wrong? I feel like I am overlooking something essential!
#> # A tibble: 1 x 2
#> `1000` `1500`
#> <dbl> <dbl>
#> 10 1
#> 5 2