# Define a function to generate random strings of a specified length 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:50, 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:9, num_rows*(num_cols-1), replace = TRUE)), ncol = num_cols-1)) # 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) }