How to transpose str(), skim(), glimpse() ?

Hi,
My question is how to transpose str(), skim(), glimpse() in order to display variables in columns
not in rows like they do ? Sort of like in displaying tibbles but I do not want to change a table to tibble every time.

when I do:

skimr::skim(wages) %>% t()

it displays nonsens.
thanks

str can only be printed

str does not return anything, for efficiency reasonsβ€”help(str)

t(skimr::skim(mtcars))
#>               1             2             3             4            
#> skim_type     "numeric"     "numeric"     "numeric"     "numeric"    
#> skim_variable "mpg"         "cyl"         "disp"        "hp"         
#> n_missing     "0"           "0"           "0"           "0"          
#> complete_rate "1"           "1"           "1"           "1"          
#> numeric.mean  " 20.090625"  "  6.187500"  "230.721875"  "146.687500" 
#> numeric.sd    "  6.0269481" "  1.7859216" "123.9386938" " 68.5628685"
#> numeric.p0    "10.400"      " 4.000"      "71.100"      "52.000"     
#> numeric.p25   " 15.42500"   "  4.00000"   "120.82500"   " 96.50000"  
#> numeric.p50   " 19.200"     "  6.000"     "196.300"     "123.000"    
#> numeric.p75   " 22.80"      "  8.00"      "326.00"      "180.00"     
#> numeric.p100  " 33.900"     "  8.000"     "472.000"     "335.000"    
#> numeric.hist  "▃▇▅▁▂"       "▆▁▃▁▇"       "β–‡β–ƒβ–ƒβ–ƒβ–‚"       "▇▇▆▃▁"      
#>               5             6             7             8            
#> skim_type     "numeric"     "numeric"     "numeric"     "numeric"    
#> skim_variable "drat"        "wt"          "qsec"        "vs"         
#> n_missing     "0"           "0"           "0"           "0"          
#> complete_rate "1"           "1"           "1"           "1"          
#> numeric.mean  "  3.596563"  "  3.217250"  " 17.848750"  "  0.437500" 
#> numeric.sd    "  0.5346787" "  0.9784574" "  1.7869432" "  0.5040161"
#> numeric.p0    " 2.760"      " 1.513"      "14.500"      " 0.000"     
#> numeric.p25   "  3.08000"   "  2.58125"   " 16.89250"   "  0.00000"  
#> numeric.p50   "  3.695"     "  3.325"     " 17.710"     "  0.000"    
#> numeric.p75   "  3.92"      "  3.61"      " 18.90"      "  1.00"     
#> numeric.p100  "  4.930"     "  5.424"     " 22.900"     "  1.000"    
#> numeric.hist  "▇▃▇▅▁"       "▃▃▇▁▂"       "▃▇▇▂▁"       "▇▁▁▁▆"      
#>               9             10            11           
#> skim_type     "numeric"     "numeric"     "numeric"    
#> skim_variable "am"          "gear"        "carb"       
#> n_missing     "0"           "0"           "0"          
#> complete_rate "1"           "1"           "1"          
#> numeric.mean  "  0.406250"  "  3.687500"  "  2.812500" 
#> numeric.sd    "  0.4989909" "  0.7378041" "  1.6152000"
#> numeric.p0    " 0.000"      " 3.000"      " 1.000"     
#> numeric.p25   "  0.00000"   "  3.00000"   "  2.00000"  
#> numeric.p50   "  0.000"     "  4.000"     "  2.000"    
#> numeric.p75   "  1.00"      "  4.00"      "  4.00"     
#> numeric.p100  "  1.000"     "  5.000"     "  8.000"    
#> numeric.hist  "▇▁▁▁▆"       "▇▁▆▁▂"       "▇▂▅▁▁"
t(dplyr::glimpse(mtcars))
#> Rows: 32
#> Columns: 11
#> $ mpg  <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8,…
#> $ cyl  <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 8,…
#> $ disp <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.8, 16…
#> $ hp   <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180, 180…
#> $ drat <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3.92,…
#> $ wt   <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150, 3.…
#> $ qsec <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.90, 18…
#> $ vs   <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,…
#> $ am   <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,…
#> $ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3,…
#> $ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2,…
#>      Mazda RX4 Mazda RX4 Wag Datsun 710 Hornet 4 Drive Hornet Sportabout
#> mpg      21.00        21.000      22.80         21.400             18.70
#> cyl       6.00         6.000       4.00          6.000              8.00
#> disp    160.00       160.000     108.00        258.000            360.00
#> hp      110.00       110.000      93.00        110.000            175.00
#> drat      3.90         3.900       3.85          3.080              3.15
#> wt        2.62         2.875       2.32          3.215              3.44
#> qsec     16.46        17.020      18.61         19.440             17.02
#> vs        0.00         0.000       1.00          1.000              0.00
#> am        1.00         1.000       1.00          0.000              0.00
#> gear      4.00         4.000       4.00          3.000              3.00
#> carb      4.00         4.000       1.00          1.000              2.00
#>      Valiant Duster 360 Merc 240D Merc 230 Merc 280 Merc 280C Merc 450SE
#> mpg    18.10      14.30     24.40    22.80    19.20     17.80      16.40
#> cyl     6.00       8.00      4.00     4.00     6.00      6.00       8.00
#> disp  225.00     360.00    146.70   140.80   167.60    167.60     275.80
#> hp    105.00     245.00     62.00    95.00   123.00    123.00     180.00
#> drat    2.76       3.21      3.69     3.92     3.92      3.92       3.07
#> wt      3.46       3.57      3.19     3.15     3.44      3.44       4.07
#> qsec   20.22      15.84     20.00    22.90    18.30     18.90      17.40
#> vs      1.00       0.00      1.00     1.00     1.00      1.00       0.00
#> am      0.00       0.00      0.00     0.00     0.00      0.00       0.00
#> gear    3.00       3.00      4.00     4.00     4.00      4.00       3.00
#> carb    1.00       4.00      2.00     2.00     4.00      4.00       3.00
#>      Merc 450SL Merc 450SLC Cadillac Fleetwood Lincoln Continental
#> mpg       17.30       15.20              10.40              10.400
#> cyl        8.00        8.00               8.00               8.000
#> disp     275.80      275.80             472.00             460.000
#> hp       180.00      180.00             205.00             215.000
#> drat       3.07        3.07               2.93               3.000
#> wt         3.73        3.78               5.25               5.424
#> qsec      17.60       18.00              17.98              17.820
#> vs         0.00        0.00               0.00               0.000
#> am         0.00        0.00               0.00               0.000
#> gear       3.00        3.00               3.00               3.000
#> carb       3.00        3.00               4.00               4.000
#>      Chrysler Imperial Fiat 128 Honda Civic Toyota Corolla Toyota Corona
#> mpg             14.700    32.40      30.400         33.900        21.500
#> cyl              8.000     4.00       4.000          4.000         4.000
#> disp           440.000    78.70      75.700         71.100       120.100
#> hp             230.000    66.00      52.000         65.000        97.000
#> drat             3.230     4.08       4.930          4.220         3.700
#> wt               5.345     2.20       1.615          1.835         2.465
#> qsec            17.420    19.47      18.520         19.900        20.010
#> vs               0.000     1.00       1.000          1.000         1.000
#> am               0.000     1.00       1.000          1.000         0.000
#> gear             3.000     4.00       4.000          4.000         3.000
#> carb             4.000     1.00       2.000          1.000         1.000
#>      Dodge Challenger AMC Javelin Camaro Z28 Pontiac Firebird Fiat X1-9
#> mpg             15.50      15.200      13.30           19.200    27.300
#> cyl              8.00       8.000       8.00            8.000     4.000
#> disp           318.00     304.000     350.00          400.000    79.000
#> hp             150.00     150.000     245.00          175.000    66.000
#> drat             2.76       3.150       3.73            3.080     4.080
#> wt               3.52       3.435       3.84            3.845     1.935
#> qsec            16.87      17.300      15.41           17.050    18.900
#> vs               0.00       0.000       0.00            0.000     1.000
#> am               0.00       0.000       0.00            0.000     1.000
#> gear             3.00       3.000       3.00            3.000     4.000
#> carb             2.00       2.000       4.00            2.000     1.000
#>      Porsche 914-2 Lotus Europa Ford Pantera L Ferrari Dino Maserati Bora
#> mpg          26.00       30.400          15.80        19.70         15.00
#> cyl           4.00        4.000           8.00         6.00          8.00
#> disp        120.30       95.100         351.00       145.00        301.00
#> hp           91.00      113.000         264.00       175.00        335.00
#> drat          4.43        3.770           4.22         3.62          3.54
#> wt            2.14        1.513           3.17         2.77          3.57
#> qsec         16.70       16.900          14.50        15.50         14.60
#> vs            0.00        1.000           0.00         0.00          0.00
#> am            1.00        1.000           1.00         1.00          1.00
#> gear          5.00        5.000           5.00         5.00          5.00
#> carb          2.00        2.000           4.00         6.00          8.00
#>      Volvo 142E
#> mpg       21.40
#> cyl        4.00
#> disp     121.00
#> hp       109.00
#> drat       4.11
#> wt         2.78
#> qsec      18.60
#> vs         1.00
#> am         1.00
#> gear       4.00
#> carb       2.00

Thank you Technocrat, this is it.
Additionally there is a new package;

install.packages("paint", repos = c(mm = "https://milesmcbain.r-universe.dev", c(getOption("repos"))))

and I did it that way as well:

paint::paint(mtcars) %>% pivot_wider()

thanks again

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.