英文:
Create simple table from dataframe
问题
I have a small dataframe of dimension 2 x 8
(see below) and I'd like to create a simple white table with the row names "scenario 1" and "scenario 2".
How can I do this as simple as possible?
Could someone also show me how to swap the order of the columns?
dput
:
structure(list(A = list(0.934842767295597, 0.92922841571852),
B = list(0.516589250165893, 0.525067529460655), C = list(
0.867615330138182, 0.866211826128489), D = list(0.0881670095698295,
0.0834131044726853), E = list(0.85734568558549, 0.856776377557092),
F = list(1.02523463957426, 1.01379194951716), G = list(0.444709565304963,
0.419220178831526), H = c(0.22, 0.25)), row.names = c(18L,
21L), class = "data.frame")
Thank you!
EDIT:
The output should be a table with 16 values (2x8). The column 'H' should be on the left. The first row label should be 'scenario 1' and the second row label should be 'scenario 2' (these labels are currently not included in my example). The values should be rounded to two decimals. I do not want to create a fancy table, but rather a simple table that can be saved as a pdf.
英文:
I have a small dataframe of dimension 2 x 8
(see below) and I'd like to create a simple white table with the row names "scenario 1" and "scenario 2".
How can I do this as simple as possible?
Could someone also show me how to swap the order of the columns?
dput
:
structure(list(A = list(0.934842767295597, 0.92922841571852),
B = list(0.516589250165893, 0.525067529460655), C = list(
0.867615330138182, 0.866211826128489), D = list(0.0881670095698295,
0.0834131044726853), E = list(0.85734568558549, 0.856776377557092),
F = list(1.02523463957426, 1.01379194951716), G = list(0.444709565304963,
0.419220178831526), H = c(0.22, 0.25)), row.names = c(18L,
21L), class = "data.frame")
Thank you!
EDIT:
The output should be a table with 16 values (2x8). The column 'H' should be on the left. The first row label should be 'scenario 1' and the second row label should be 'scenario 2' (these labels are currently not included in my example). The values should be rounded to two decimals. I do not want to create a fancy table, but rather a simple table that can be saved as a pdf.
答案1
得分: 1
df <- 结构(列表(A = 列表(0.934842767295597, 0.92922841571852),
B = 列表(0.516589250165893, 0.525067529460655), C = 列表(
0.867615330138182, 0.866211826128489), D = 列表(0.0881670095698295,
0.0834131044726853), E = 列表(0.85734568558549, 0.856776377557092),
F = 列表(1.02523463957426, 1.01379194951716), G = 列表(0.444709565304963,
0.419220178831526), H = c(0.22, 0.25)), 行名 = c(18L,
21L), 类别 = "数据框架")
行名(df) <- c("情景 1", "情景 2")
df |>
knitr::kable()
A | B | C | D | E | F | G | H | |
---|---|---|---|---|---|---|---|---|
情景 1 | 0.9348428 | 0.5165893 | 0.8676153 | 0.08816701 | 0.8573457 | 1.025235 | 0.4447096 | 0.22 |
情景 2 | 0.9292284 | 0.5250675 | 0.8662118 | 0.0834131 | 0.8567764 | 1.013792 | 0.4192202 | 0.25 |
<sup>2023-06-29 创建,使用 reprex v2.0.2</sup>
英文:
Somethink like?:
df <- structure(list(A = list(0.934842767295597, 0.92922841571852),
B = list(0.516589250165893, 0.525067529460655), C = list(
0.867615330138182, 0.866211826128489), D = list(0.0881670095698295,
0.0834131044726853), E = list(0.85734568558549, 0.856776377557092),
F = list(1.02523463957426, 1.01379194951716), G = list(0.444709565304963,
0.419220178831526), H = c(0.22, 0.25)), row.names = c(18L,
21L), class = "data.frame")
rownames(df) <- c("scenario 1", "scenario 2")
df |>
knitr::kable()
A | B | C | D | E | F | G | H | |
---|---|---|---|---|---|---|---|---|
scenario 1 | 0.9348428 | 0.5165893 | 0.8676153 | 0.08816701 | 0.8573457 | 1.025235 | 0.4447096 | 0.22 |
scenario 2 | 0.9292284 | 0.5250675 | 0.8662118 | 0.0834131 | 0.8567764 | 1.013792 | 0.4192202 | 0.25 |
<sup>Created on 2023-06-29 with reprex v2.0.2</sup>
Otherwise please follow @r2evans suggestion and provide more context.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论