Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to repeat value in merged cells #355

Open
jameshowison opened this issue May 1, 2017 · 4 comments
Open

option to repeat value in merged cells #355

jameshowison opened this issue May 1, 2017 · 4 comments
Labels
feature a feature request or enhancement

Comments

@jameshowison
Copy link

Moving discussion from: #220 (comment)

Currently (I think) merged cells are handled by placing the value in the left-top cell of the range and placing NA in all other cells. Makes sense in many situations.

Another useful option might be to repeat the value across the previously merged range. That would, for example, be helpful in tidying files with multiple headers, as detailed here: https://howisonlab.github.io/datawrangling/Handling_multi_indexes.html#a-tidyverse-solution

However, with your suggestions from the other thread, tidyr::fill works for this sensibly if one does a little transposing:

# read, fill, and collapse 4 rows of multiple headers from merged cells
headers <- read_excel(filename, col_names = FALSE, na="..", n_max = 4)
# fill only works down or up, so have to transpose headers
long_headers = data.frame(t(headers))
long_headers <- fill(long_headers,1:4) # all four columns
headers <- data.frame(t(long_headers)) # back to vertical.

Nonetheless, an option to unmerge and fill all cells might still be useful.

@jennybc jennybc changed the title option to repeat values in unmerged cells option to repeat value in merged cells May 1, 2017
@jennybc jennybc added the feature a feature request or enhancement label May 1, 2017
@zyxdef
Copy link

zyxdef commented Jun 10, 2017

It would be quite handy to have some option like mergedcells = c("fill", "missing") with possibly some other sensible alternatives. I was going to suggest it as a feature if it weren't already suggested.

@slyrus
Copy link

slyrus commented Oct 3, 2019

+1. Merged cells are the bane of my existence.

@jtr13
Copy link

jtr13 commented Oct 12, 2019

How about fill(..., .direction = "right")?

https://github.com/tidyverse/tidyr/blob/master/R/fill.R

@paulduf
Copy link

paulduf commented Apr 16, 2024

+1. Can't believe this is not already implemented somehow.

EDIT: OK I just discovered the existence of tidyxl and unpivotr, so maybe this is the recommended way to go. Still, this adds some technical complexity to something that should be simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

6 participants