Here are a couple of approaches for this problem.
Since we don't have your data, I'll use the palmerpenguins dataset for demonstration:
library(palmerpenguins)
library(purrr)
df <- penguins[,c("species","island","sex")]
One approach is to use base R functions:
day_df <- do.call(
rbind,
lapply(
1:31,
function(i) {
df$day <- i
df
}
))
Here, we're using lapply to make a list of modified data.frames, each of which has a value, from 1 to 31, in the "day" column. We then assemble these into a single data.frame by running do.call(rbind).
Here's a second approach using the purrr package:
add_day <- function(day, df) {
df$day <- day
df
}
day_df <- map_dfr(
1:31,
add_day,
df = df
)
In this case, we're making a simple function add_day(), then using map_dfr() from purrr to assemble the data.frames into a single result.
Note: we could also use an anonymous function just like in the base example:
day_df <- map_dfr(
1:31,
function(day) {
df$day <- day
df
}
)