Comments (4)
To be clear, the output is:
> df <- data.frame( x = c(1, 2), y = c(3, 4))
> spread(df, x, y)
1 2
1 3 NA
2 NA 4
I would have expected the output to have one row:
1 2
1 3 4
from tidyr.
Me too: in the absence of an identifying column it should all be assumed to have the same identifier. This is important in nested (group) processing. Right now it's necessary to ungroup before spread to bring the identifiers into scope.
from tidyr.
I've also just run into this (tidyr 0.3.1). @hadley, can you weigh in on whether this is a bug or expected behavior?
FWIW I was trying to use spread
on the output of broom::tidy
to get the estimate
values into a single row with columns named for term
, as in:
library(tidyr)
library(broom)
library(dplyr)
d <- data_frame(x = runif(100, 0, 10),
y = 5 - x + rnorm(100))
d %>%
lm(y ~ x, data=.) %>%
tidy() %>%
select(term, estimate) %>%
spread(term, estimate) %>%
mutate(x_intercept = -`(Intercept)` / x)
#> (Intercept) x x_intercept
#> 1 5.148648 NA NA
#> 2 NA -1.010463 NA
d %>%
lm(y ~ x, data=.) %>%
tidy() %>%
select(term, estimate) %>%
mutate(dummy='') %>%
spread(term, estimate) %>%
mutate(x_intercept = -`(Intercept)` / x)
#> dummy (Intercept) x x_intercept
#> 1 5.148648 -1.010463 5.095337
Seems like a perfectly good use case for tidyr
+ broom
so I was surprised.
from tidyr.
More illuminating example:
data_frame(
key = c("a", "b", "c"),
value = c(1, 2, 3)
) %>%
spread(key, value)
This is definitely a bug
from tidyr.
Related Issues (20)
- Release tidyr 1.3.1
- separate_wider_delim changes input column names when using names_sep with cols_remove=FALSE HOT 1
- Change in pivot_wider behavior and error messages when using column numbers for `id_cols` HOT 1
- Feature request: function count the missing value
- Feature request: `.vary` in `expand_grid()`
- Solutions for a crowded namespace: selective removal of items? Any better ideas?
- int64 summation fails HOT 3
- Error in tidyr package & issue with columns being added to Markdown output where used to put into rows (no change to code) HOT 10
- keep getting the error while running RStudio R 4.3.3 on MacOS Big Sur HOT 1
- Better error message for empty tidyselect quosure HOT 2
- In `separate_wider_delim()`, could `merge` have an option for `too_many = "merge_end"`
- num_range() with multiple-specified prefixes gives alternating result HOT 1
- `slice()` behaves differently to `head()` on nested tibbles vs. unnested tibbles. HOT 2
- unnest_longer with multiple cols - values_to=glue::glue({col}_long) not working
- `drop_na()` loses extra classes for `tbl_df`s
- Use base pipe in examples HOT 3
- Feature request: `fill(.direction = "sandwich")` HOT 1
- typos
- Intermittent "reached elapsed time limit" when nesting
- Tibble error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tidyr.