Generating Synthetic Data with Variable Sequencing and Mean Value Setting
library(effects)

gen_seq <- function(data, x1, x2, x3, x4) {
  # Create a new data frame with the specified variables set to their mean and one variable sequenced from its minimum to maximum value
  new_data <- data
  
  # Set specified variables to their mean
  for (i in c(x1, x2, x3)) {
    new_data[[i]] <- mean(new_data[[i]], na.rm = TRUE)
  }
  
  # Sequence the specified variable from its minimum to maximum value
  seq_x4 <- seq(min(new_data[[x4]]), max(new_data[[x4]]), length.out = 100)
  
  # Add the sequenced variable to the new data frame
  new_data[[x4]] <- seq_x4
  
  return(new_data)
}

# Test the function
data <- data.frame(x1 = rnorm(100), x2 = rnorm(100), x3 = rnorm(100), x4 = rnorm(100))
result <- gen_seq(data, "test1", "test2", "test3", "test4")

Last modified on 2024-03-30