0

I'm trying to create a table in which the headers can change from time to time which means that the headers are not static.

Kindly see the sample below.

Create variable months with the code below

testing<-format(Sys.Date(),"%m")
testing<-as.integer(testing)
testing<-testing -(2)
last_2_month<-month.name[testing]

teaser<-format(Sys.Date(),"%m")
teaser<-as.integer(teaser)
teaser<-teaser-1
last.month<-month.name[teaser]

creating table

Point <- c("Average success rate", "Average processing duration", "Average daily count", "Total count processed")
ss <- c(23, 41, 32, 58)
sss <- c("Jon", "Bill", "Maria", "Ben")
dframes <- data.frame(Point,last.month,last_2_month) #creating table the table

what I want is that the variable for both last.month and last_2_month should display the true month name/variable eg January and February in the table

Point January Feburary
Average success rate CSW Data
Average processing duration CSW Data
Average daily count CSW Data
Total count processed CSW Data

Glo CSW Data

danlooo
  • 10,067
  • 2
  • 8
  • 22
Yomi.blaze93
  • 401
  • 3
  • 10

1 Answers1

0

This will grab all columns containing the term month and create a new column for each month:

dframes %>% pivot_longer(matches("month")) %>%
pivot_wider(names_from = value, values_from = name)
#># A tibble: 4 × 3
#>  Point                       February   January     
#>  <chr>                       <chr>      <chr>       
#>1 Average success rate        last.month last_2_month
#>2 Average processing duration last.month last_2_month
#>3 Average daily count         last.month last_2_month
#>4 Total count processed       last.month last_2_month

However, according to your example, there is no information on how to map this to cell values e.g. CSW or Data

danlooo
  • 10,067
  • 2
  • 8
  • 22