I'm trying to create a loop where if x is below a certain value, one dataframe is produced, and if it is above a certain value, a different one is produced, within an ifelse statement. Here is some dummy data approximating what I'm trying to do:
population <- sample(c(1000:9999), 10)
year <- sample(c(2009:2020), 10)
for(x in 1:10){
df <- ifelse(x < 5, as.data.frame(population), as.data.frame(year))
print(head(df))
}
However, the df that is produced just ends up being a list instead of a matrix of observations and variables. Is there a way to fix this?