Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205423

I am looking for the quickest code to generate a table from a data frame [duplicate]

$
0
0

This question already has an answer here:

Does anybody know the cleanest and quickest code in R Studio to create the table from the given data frame in table 1?

With few amounts of different variables in each column, I can handle this with dirty solutions but I have more than 40 models over 200types with 10 years period.

data frame

to create

df <-
structure(list(Model = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L), .Label = c("Model A", "Model B", "Model C"), class = "factor"), 
    Type = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 4L, 
    5L, 6L, 4L, 5L, 6L, 4L, 5L, 6L, 8L, 9L, 7L, 8L, 9L, 7L, 8L, 
    9L), .Label = c("TypeA1", "TypeA2", "TypeA3", "TypeB1", "TypeB2", 
    "TypeB3", "TypeC1", "TypeC2", "TypeC3"), class = "factor"), 
    Year = c(2016L, 2016L, 2016L, 2017L, 2017L, 2017L, 2018L, 
    2018L, 2018L, 2016L, 2016L, 2016L, 2017L, 2017L, 2017L, 2018L, 
    2018L, 2018L, 2016L, 2016L, 2017L, 2017L, 2017L, 2018L, 2018L, 
    2018L), Price = c(10L, 11L, 12L, 11L, 12L, 13L, 12L, 13L, 
    14L, 15L, 16L, 17L, 16L, 17L, 18L, 17L, 18L, 19L, 17L, 18L, 
    19L, 18L, 19L, 20L, 19L, 20L)), class = "data.frame", row.names = c(NA, 
-26L))

Viewing all articles
Browse latest Browse all 205423

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>