Making a table in R from Excel data

Hello,

how would I be able to create a table like this
Picture1
in R?

I have tried to make a data frame for this and thing are not working out for me. How would I make a simple table like the Excel one shown in the photo?

You can make it manually in R like this:

DF <- data.frame(AB=c("RD","CS"),YS=c(1,2),QS=c(3,4),QC=c(5,6),
                  HF=c(7,8),KJ=c(9,10),PL=c(11,23),KN=c(13,14))
DF
  AB YS QS QC HF KJ PL KN
1 RD  1  3  5  7  9 11 13
2 CS  2  4  6  8 10 23 14

It is also easy to read the data from an Excel file. The readxl package has the read_excel function that does that.

You could use dplyr::tribble().

dplyr::tribble(
  ~AB, ~YS, ~QS, ~QC, ~HF, ~KJ, ~PL, ~KN,
  "RD", 1, 3, 5, 7, 9, 11, 13,
  "CS", 2, 4, 6, 8, 10, 12, 14
)
#> # A tibble: 2 x 8
#>   AB       YS    QS    QC    HF    KJ    PL    KN
#>   <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 RD        1     3     5     7     9    11    13
#> 2 CS        2     4     6     8    10    12    14

Created on 2021-12-06 by the reprex package (v2.0.1)

This topic was automatically closed 21 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.