Very simple question. I am using an excel sheet that has two rows for the column headings; how can I convert these two row headings into one? Further, these headings don’t start at the top of the sheet.
Thus, I have DF1
Temp Press Reagent Yield A Conversion etc
degC bar /g % %
1 2 3 4 5
6 7 8 9 10
and I want,
Temp degC Press bar Reagent /g Yield A % Conversion etc
1 2 3 4 5
6 7 8 9 10
Using colnames(DF1) returns the upper names, but getting the second line to merge with the upper one keeps eluding me.
Using your data, modified to quote text fields that contain the separator (get whatever tool you used to generate the file to quote text fields for you!)
this snippet of code below reads the file in two steps
skip = 2means skip the first 2 linessapply()where wepaste(x, collapse = " ")the strings in the columns of thelabsdata frame. These are assigned to thenamesofdatHere is the code:
The code, when runs produces:
In your case, you’ll want to modify the
read.table()calls to point at the file on your file system, so usefile = "foo.txt"in place oftext = txtin the code chunk, where"foo.txt"is the name of your file.Also, if these headings don’t start at the top of the file, then increase
skipto2+nwherenis the number of lines before the two header rows. You’ll also need to addskip = nto the secondread.table()call which generateslabs, wherenis again the number of lines before the header lines.