I saw this question: Import Excel Files into R. The user has only provided data via a link to Google Drive. Of course this link could disappear and make the question meaningless, so this seems wrong. However, the question is specifically about loading an Excel file (that presumably has features that make it difficult to load). For code and some types of data, there are other ways to provide the required information within the question, but what is the OP supposed to do when it must be an Excel file? Is there a better (more permanent) way for the poster to provide this data?
3 Answers
TL;DR - The question should include the Excel structure as monospace code, but this question is likely a duplicate; see below.
To address your comment, not every question requires an MCVE; an MCVE is required for questions about existing code that does not work. In a question that is more conceptual or broad in nature, an MCVE is not required or really appropriate. It's hard to describe such kinds of questions because these days Stack Overflow is geared so heavily toward questions about existing code that doesn't work, but there remain several other kinds of questions that the Help Center says are on-topic and OK to ask here.
In a question about Excel data, it is not possible to import your data directly, as Stack Overflow does not (yet? Maybe that's too hopeful...) have a Spreadsheet Snippet feature akin to their Stack Snippet feature. Handily, however, spreadsheets of data are essentially a big table, and there is a way to format data to appear like a table:
How to put tables in Stack Overflow?
Is there Markdown to create tables?
Now, despite what your title asks, what you seem to be asking is not really how to visually represent Excel data in a post; it's asking about some aspect of an Excel file's format that is causing problems with R, but looking at his question and his Excel file on Google Drive, his problem is indeed that he has some kind of weird hybrid column header system going on:
In this case, he should post it as monospace code to help identify exactly what his layout is. Something like:
-----------------
- Data - Data 2 -
- Unified Data -
-----------------
- a - b -
And so on.
In this particular case, however, the asker's question is, in my opinion, too broad. He's asking for--essentially--a tutorial on how to import Excel code into R, and doesn't explain at all how his code is different or "more complicated" to use his words. He doesn't specify how the output needs to look in R, and he doesn't show any attempt to date of him trying to import the data into R... so we don't know what his attempt looks like, or if he has even made one.
Most helpfully, however, is that this question is likely a duplicate of Read csv with two headers into a data.frame or of Reading two-line headers in R. A cursory google search also turns up a half-dozen other similar questions, as well.
-
1Excellent: works as an answer to this Meta question and to the trigger SO question as well.– APCCommented May 19, 2018 at 7:17
-
1I would not trust anyone to manually reproduce that table structure in ASCII-art formatting. Even in your tiny example, there's no border between the
Data - Data 2
bit and theUnified Data
bit, making it hard to see what the structure is intended to be. Unless there's some tool that parses this format, I don't see any benefit to being able to copy-paste it, and it doesn't seem to be useful for searches either, so I think a screenshot is probably more useful. Commented May 20, 2018 at 19:14 -
1@user2357112 My example was just a 50,000 foot view to illustrate how to format a table. It should be trivial to extrapolate from that and recreate the table structure in the screenshot, I just did not want to expend the time to do so. I agree a screenshot is probably as useful, but there is a stigma against pasting data via screenshots here; my suggestion was given with that stigma in mind.– TylerHCommented May 20, 2018 at 20:05
My current comment prompt for input and/or output sample data is to provide the OP with the following procedure:
- Copy some sample data from Excel
- Go to https://www.tablesgenerator.com/markdown_tables
- Paste the data (File -> Paste table data)
- Click Generate.
- Click Copy to clipboard
- Paste the Markdown table into the question.
This works very well, for the most part; aside from merged cells, which AFAICT aren't really handled ATM by CommonMark.
Ideally, SE should implement something similar without resorting to a third-party website.
-
Maybe an interesting FR: meta.stackexchange.com/a/360046/158100– reneCommented Mar 10, 2021 at 8:56
-
1
In addition to the accepted answer, something worthy of comment is the fact that if you paste tab-separated spaces into a excel cell, it will be pasted in the corresponding cells, assuming there are no row-spans or col-spans. So posting a monospaced version of the dataset (if it's not too long) will suffice
[1,2,3, ..., 1000000]
. Is there no way to describe the properties of the data without including the entire table?