# Define a function to generate random strings of a specified length library(gt) library(dplyr) random_string <- function(length) { char_set <- c(letters, LETTERS, 0:9) paste0(sample(char_set, length, replace = TRUE), collapse = "") } # Loop through 100 times to create 100 CSV files for (i in 1:100) { # Generate a random number of rows between 10 and 50 num_rows <- sample(10:20, 1) # Generate a random number of columns between 3 and 10 num_cols <- sample(3:10, 1) # Create a data frame with the specified number of rows and columns df <- data.frame(ID = replicate(num_rows, random_string(6)), matrix(paste0("C", rep(1:(num_cols-1), each = num_rows), sample(2:4, num_rows*(num_cols-1), replace = TRUE)), ncol = num_cols-1), stringsAsFactors = FALSE) # Set the column names for the additional columns colnames(df)[-1] <- paste0("D", 1:(num_cols-1)) # Write the data frame to a CSV file with the appropriate name filename <- sprintf("P%03d.csv", i) write.csv(df, filename, row.names = FALSE, quote = FALSE) } #P004 <- read.csv("P004.csv") #P004table = gt(read.csv("P004.csv")) #P004table <- P004table %>% # tab_row_group( # rows = which(rownames(P004) %in% rownames(P004[P004$D1 == "C12", ])), # label = "P004A" # ) %>% # tab_row_group( # rows = which(rownames(P004) %in% rownames(P004[P004$D1 == "C13", ])), # label = "P004B" # ) #P004 <- P004 %>% # mutate(Type = case_when( # D1 == "C12" & D2 == "C23" & D3 == "C32" ~ "P004A", # D1 == "C12" & D2 == "C23" & D3 == "C33" ~ "P004B", # TRUE ~ "Uncat" # )) #P004A <- subset(P004, D1 == "C12" & D2 == "C23" & D3 == "C32") #P004B <- subset(P004, D1 == "C12" & D2 == "C23" & D3 == "C33") #P004Z=rbind(P004A,P004B) #head(P004) #P004_table <- gt(P004) #table <- gt(P004) #table <- table %>% # tab_row_group(groups = list("Type")) #library(gt) # Create a data frame #data <- data.frame( # Name = c("John", "Emily", "Michael", "Emma", "Daniel"), # Age = c(25, 32, 41, 29, 36), # Country = c("USA", "Canada", "UK", "Australia", "USA") #) # Create a gt table #table <- gt(data) # Select rows based on a condition #selected_rows <- data[data$Age > 30, ] # Select rows where Age is greater than 30 # Add row groups #table <- table %>% # tab_row_group( # rows = which(rownames(data) %in% rownames(selected_rows)), # Get row indices of selected rows # label = "Group 1 (Age > 30)" # ) # Print the table #print(table) #library(gt) # Create a data frame #data <- data.frame( # Name = c("John", "Emily", "Michael", "Emma", "Daniel"), # Age = c(25, 32, 41, 29, 36), # Country = c("USA", "Canada", "UK", "Australia", "USA") #) # Create a gt table #table <- gt(data) # Select rows based on a condition #selected_rows <- data[data$Age > 30, ] # Select rows where Age is greater than 30 # Add row groups #table <- table %>% # tab_row_group( # rows = which(rownames(data) %in% rownames(selected_rows)), # Get row indices of selected rows # label = "Group 1 (Age > 30)" # ) # Print the table #print(table) #gtsave(P004table, file = "P004_table.html") #system("wkhtmltopdf P004_table.html table.pdf")