Hi,
Welcome to the RStudio community!
Here is a way of doing that using an the lapply function. It will iterate over every column in your data and output a list, which can then be pasted back together into a data frame
set.seed(3) #Only needed for reproducibility
#Test data
myData = data.frame(x = sample(1:3, 5, replace = T),
y = sample(LETTERS[1:3], 5, replace = T))
myData
#> x y
#> 1 1 C
#> 2 2 B
#> 3 3 C
#> 4 2 A
#> 5 3 B
#Create new data
nNew = 10
newData = lapply(myData, function(x){
#Get the freq of each value
freq = table(x)
#Sample new values
sample(sort(unique(x)), nNew, prob = freq / sum(freq), replace = T)
})
#Create data frame from each sampling
newData = as.data.frame(newData)
newData
#> x y
#> 1 2 C
#> 2 2 B
#> 3 2 B
#> 4 2 B
#> 5 2 C
#> 6 2 B
#> 7 3 B
#> 8 3 A
#> 9 1 B
#> 10 3 C
Created on 2022-03-28 by the reprex package (v2.0.1)
Note that sample() is useful when you have discrete values, but for continuous values you should use other functions.
Hope this helps,
PJ