I have created a table for cars and speed. The column heading as shown is the cars and the row headings are the summary of the characteristics I was searching for to be in the table. I prefer the N, Median and Range to be the column heading (TOP) and the row heading to be the cars (At the SIDE). Can you help me change my code to suit that, Attached is a pic of the table
My Code
library(datapasta)
datapasta::df_paste(head(dff, 70)[, c('car', 'speed')])
#> Error in head(dff, 70): object 'dff' not found
data.frame( stringsAsFactors = FALSE,
NA,
car = c("Honda","Opel",
"Toyota","Ford","Toyota",
"Toyota","Toyota",
"Toyota","Toyota",
"Toyota","Opel",
"Opel","Opel",
"Opel","Opel","Opel",
"Opel","Opel",
"Opel","Opel","Opel",
"Opel","Opel",
"Opel","Opel","Opel",
"Ford","Ford",
"Honda","Honda","Honda",
"Honda","Honda",
"Honda","Honda",
"Honda","Honda",
"Honda","Honda",
"Honda","Honda","Honda",
"Honda","Honda",
"Honda","Honda",
"Honda","Honda",
"Honda","Honda","Honda",
"Honda","Honda",
"Honda","Honda",
"Honda","Honda",
"Honda","Ford","Ford",
"Ford","Ford",
"Ford","Ford","Ford",
"Ford","Ford",
"Ford","Ford","Ford"),
speed = c(0.0818884144530994,
0.078202618461924,
0.0923996477945826,
0.0833895373090655,
0.0654271133558503,
0.104902087082777,
0.0767497512256455,
0.0768176971270742,
0.0712864905867507,
0.0554218586661056,
0.0850360296771161,
0.057954145633874,
0.0441854480859481,
0.0881234075504796,
0.0639960050103843,
0.0620009991911811,
0.104363010616978,
0.0794749032774448,
0.0639931924725228,
0.0347553634870904,
0.0235164440970578,
0.000945735768549479,
0.0951332350399264,
0.0848849882638771,
0.0770268456523483,
0.0860962939374158,
0.0779784304434212,
0.0700250314203401,
0.0979442195442822,
0.0895676676419504,
0.145633658479367,
0.114931834231455,
0.0907671090187226,
0.118083514719288,
0.0903243829523317,
0.0852324890285871,
0.0196699224014573,
0.080910276397263,
0.0667256842832578,
0.100828213795925,
0.0878058668694595,
0.0758022260504243,
0.106719838699154,
0.0920508745930191,
0.0710548353544975,
0.0859097610562796,
0.0692502648434324,
0.0642848032824688,
0.0934410581211051,
0.0901226640111047,
0.0880892316582102,
0.0526000795151807,
0.0487590677497554,
0.0362328359734826,
0.130861058707153,
0.115286968138184,
0.0973709227872183,
0.075845698962114,
0.0726245579593528,
0.0660583859152627,
0.0432445861280246,
0.0326512563074741,
0.0833250468064319,
0.0712792343009829,
0.0662704232419949,
0.0267930511166544,
0.0195822515826592,
0.0182287564631037,
0.0565616222676817,
0.0462813673349305)
)#Import the master excel file and Choose the sheet we will be using for analysis.The sheet number is the last digit to write in the code. A window pops-up for you to choose the location of the file in question.
#> NA. car speed
#> 1 NA Honda 0.0818884145
#> 2 NA Opel 0.0782026185
#> 3 NA Toyota 0.0923996478
#> 4 NA Ford 0.0833895373
#> 5 NA Toyota 0.0654271134
#> 6 NA Toyota 0.1049020871
#> 7 NA Toyota 0.0767497512
#> 8 NA Toyota 0.0768176971
#> 9 NA Toyota 0.0712864906
#> 10 NA Toyota 0.0554218587
#> 11 NA Opel 0.0850360297
#> 12 NA Opel 0.0579541456
#> 13 NA Opel 0.0441854481
#> 14 NA Opel 0.0881234076
#> 15 NA Opel 0.0639960050
#> 16 NA Opel 0.0620009992
#> 17 NA Opel 0.1043630106
#> 18 NA Opel 0.0794749033
#> 19 NA Opel 0.0639931925
#> 20 NA Opel 0.0347553635
#> 21 NA Opel 0.0235164441
#> 22 NA Opel 0.0009457358
#> 23 NA Opel 0.0951332350
#> 24 NA Opel 0.0848849883
#> 25 NA Opel 0.0770268457
#> 26 NA Opel 0.0860962939
#> 27 NA Ford 0.0779784304
#> 28 NA Ford 0.0700250314
#> 29 NA Honda 0.0979442195
#> 30 NA Honda 0.0895676676
#> 31 NA Honda 0.1456336585
#> 32 NA Honda 0.1149318342
#> 33 NA Honda 0.0907671090
#> 34 NA Honda 0.1180835147
#> 35 NA Honda 0.0903243830
#> 36 NA Honda 0.0852324890
#> 37 NA Honda 0.0196699224
#> 38 NA Honda 0.0809102764
#> 39 NA Honda 0.0667256843
#> 40 NA Honda 0.1008282138
#> 41 NA Honda 0.0878058669
#> 42 NA Honda 0.0758022261
#> 43 NA Honda 0.1067198387
#> 44 NA Honda 0.0920508746
#> 45 NA Honda 0.0710548354
#> 46 NA Honda 0.0859097611
#> 47 NA Honda 0.0692502648
#> 48 NA Honda 0.0642848033
#> 49 NA Honda 0.0934410581
#> 50 NA Honda 0.0901226640
#> 51 NA Honda 0.0880892317
#> 52 NA Honda 0.0526000795
#> 53 NA Honda 0.0487590677
#> 54 NA Honda 0.0362328360
#> 55 NA Honda 0.1308610587
#> 56 NA Honda 0.1152869681
#> 57 NA Honda 0.0973709228
#> 58 NA Honda 0.0758456990
#> 59 NA Ford 0.0726245580
#> 60 NA Ford 0.0660583859
#> 61 NA Ford 0.0432445861
#> 62 NA Ford 0.0326512563
#> 63 NA Ford 0.0833250468
#> 64 NA Ford 0.0712792343
#> 65 NA Ford 0.0662704232
#> 66 NA Ford 0.0267930511
#> 67 NA Ford 0.0195822516
#> 68 NA Ford 0.0182287565
#> 69 NA Ford 0.0565616223
#> 70 NA Ford 0.0462813673
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(readxl)
library("xlsx")
Sheet <- read.xlsx(file.choose(),1)
#> Error in file.choose(): file choice cancelled
#######Table
#preparing
library(gtsummary)
library(readxl)
library(flextable)
#>
#> Attaching package: 'flextable'
#> The following objects are masked from 'package:gtsummary':
#>
#> as_flextable, continuous_summary
library(officer)
#>
#> Attaching package: 'officer'
#> The following object is masked from 'package:readxl':
#>
#> read_xlsx
dff <- Sheet
#> Error in eval(expr, envir, enclos): object 'Sheet' not found
#create the table
tbl<-dff %>%
select(car, speed) %>%
tbl_summary(by = car,type = all_continuous() ~ "continuous2",
label = list(speed ~ "Speed", car ~ "Car Type"),
digits = all_continuous() ~ 3,
statistic = all_continuous() ~ c("{N_nonmiss}",
"{median} ({p25}, {p75})",
"{min}, {max}"),) %>%
modify_header(all_stat_cols() ~ "**{level}**" )%>%
modify_caption("Car according to Speed") %>%
bold_labels()%>%
add_p(pvalue_fun = ~style_pvalue(.x, digits = 2)) %>%
bold_p()%>%
as_flex_table()
#> Error in select(., car, speed): object 'dff' not found
tbl
#> function (src, ...)
#> {
#> UseMethod("tbl")
#> }
#> <bytecode: 0x000000001ba4b900>
#> <environment: namespace:dplyr>
Created on 2022-06-22 by the reprex package (v2.0.1)