Hi @tommyteo,
Welcome to the RStudio Community Forum.
It’s not entirely clear what your required output is, but this code produces a dataframe:
set.seed(1984)
taobien <- function(obs,n){
stt <- c(1:obs)
tapbien <- cbind(stt)
for (i in 1:n){
bien <-round(rnorm(obs,10,2),1)
bien <- data.frame(bien)
colnames(bien)<-paste0("Bien",i)
tapbien <-cbind(tapbien,bien)
}
return(tapbien)
}
keep <- taobien(20,5)
head(keep)
stt Bien1 Bien2 Bien3 Bien4 Bien5
1 1 10.8 12.5 10.1 8.5 10.4
2 2 9.4 10.9 11.6 11.3 11.1
3 3 11.3 8.7 9.8 13.3 9.1
4 4 6.3 11.8 7.3 9.3 7.1
5 5 11.9 10.0 12.5 13.2 10.3
6 6 12.4 10.5 12.4 9.4 12.3