I would like to ask how do i add/append new observations to empty r dataframe. I will be running a loop and I want to update this dataframe as and when the loop is running.
say for instance, I have this dataframe:
error <- data.frame(error_code = character(), row_no = character(), sleep_time = character(), time_scrape = character())
the loop that I will be running is:
for (i in 1:10) {
if (i %% 2 == 0) {
error_code = i
row_no = i
sleep_time = 60
time_scrape = i
}
error <- error %>%
add_row(error_code = error_code, row_no = row_no, sleep_time = sleep_time, time_scrape = time_scrape)
}
I want to add in the values based on the value I get from the loop
I tried using add_row but it doesnt work. how should I do this such that at the end, I will get something like this: (p/s: this table below is created manually and not by the code above)
error_code row_no sleep_time time_scrape
1 2 2 60 2
2 4 4 60 4