How can I turn the following text file into a nice RMarkDown table?

Checster

I have several .txt files that I would like to convert into a nice table in RMarkDown. An example of one would be a file containing the following text:

|name|Tin|Tout|Hin|Hout|DT min/2|alpha|
|-----|-----|-----|-----|-----|-----|-----|
|airHEATER_1|3.09|55|0|834|5|1|
|airHEATER_2|4.35|60|0|894.47|5|1|
|airHEATER_3|35.63|70|0|553.51|5|1|
|airHEATER_4|59.78|75|0|245.52|5|1|
|airHEATER_5|78.49|85|0|104.97|5|1|

I have tried everything. The kable function returns nonsense, I have also tried readLines() and read.table() but no luck. I tried converting the .txt file contents into a dataframe with the as.data.drame() function but I get a one-column dataframe with the .txt whole lines as rows, instead of 7 columns.

How would you do it ? I ran out of options here :/

stefan

Using read.table with sep="|" and some data cleaning you could do:

---
output: html_document
date: "2022-11-09"
---

```{r}
dat <- read.table(text = "|name|Tin|Tout|Hin|Hout|DT min/2|alpha|
|-----|-----|-----|-----|-----|-----|-----|
|airHEATER_1|3.09|55|0|834|5|1|
|airHEATER_2|4.35|60|0|894.47|5|1|
|airHEATER_3|35.63|70|0|553.51|5|1|
|airHEATER_4|59.78|75|0|245.52|5|1|
|airHEATER_5|78.49|85|0|104.97|5|1|", sep = "|", header = TRUE, check.names = FALSE)
```

```{r}
dat <- dat[-c(1, ncol(dat))]
dat <- dat[!grepl("^-", dat[[1]]), ]
```

```{r}
knitr::kable(dat)
```

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I include a PNG file as a numbered table in Rmarkdown?

How can I turn the following dataframe into a multi-index dataframe?

How can I scramble a text file table, with a table

How can I format the following text?

How can i make my turn my text file to 40x40 matrix

How can I parse a text file with scientific notation ( in tensor format) and turn them into float

How to turn the result of summary() into a nice looking data table

How can I write a regex to extract data preceding and following a specific expression in a text file?

Turn Exploded text file into table

How can I modifiy the positions of the text and logo on RMarkdown title slide

How can I embed a plot within a RMarkdown table?

How can I generate a paged table with a title in RMarkdown?

R: How can I code repetitive output into an Rmarkdown file?

How can I verify `nice` is working?

rand() function, how can I get the nice

How do I turn a text file with a single column into a matrix?

How can i turn text to link version with javascript?

How can I turn a text area into an input stream in java?

How can i get the text of a paragraph and then turn it into an integer in HTML

How can I turn a list of form responses into a summary table?

How can I turn a dataframe into a markdown vertical table?

How can I turn off "suggestions table?" in VS Code?

How can I line up the text inside a <span> following a <button>

Using XPath, how can I exact text following a tag?

How can I manipulate/extract info from the following table in J

How can I fix Table Row Insertion of the following code?

How can I have nice file names & efficient storage usage in my Foundry Magritte dataset export?

How can I turn `file` tool into a predicate for `find`?

How can I turn two database tables in to a multidimensional JSON file?

TOP Ranking

HotTag

Archive