Faster way to append row.

I have a dataframe in the following format

df_151=as.POSIXct("1976-09-03 23:00:00")

I am able to add a row with the following code


As I am dealing with 1000s of rows, this code took me 4-5 min to complete it with other operations.
I will be grateful if anyone could provide an alternative way to get faster or how can I avoid using $ in the above code.

Can you give us a description of the overall problem or analysis you are tackling?
I suspect that there are a number of ways to do what you want and all easier than that add_row command.

For example, here is a simple way to generate a series of times and dates

seq(from = ymd_hm("2000-01-01 00:00"), to = ymd_hm("2000-12-30 11:59"), by =  "10 min")

Does this mean that you have those data or that you need to create the data?

This is again a different scenario for me.

I need to add 10 min to each row of the following data frame inside a loop.

id <- "146Ng_b6wCcVNAVGwpej68yAkguZPHBak"
Data <- readr::read_csv(paste0("", id, "&export=download"),
                        col_names = TRUE

Thank you for the data but I still do not understand what you are doing in substantive terms . Are you saying that for every timedate you want to add a date that is 10 minutes greater? Thus doubling the number of timedates but only changing the overall timedate range by + 10 minutes?

Why? In terms of the research problem?

id <- "146Ng_b6wCcVNAVGwpej68yAkguZPHBak"
Data <- readr::read_csv(paste0("", id, "&export=download"),
                        col_names = TRUE
Data %>%
    mutate( newdatetime = datetime+minutes(10))

creates a second column in blink of an eye.

Are you trying to create an extra ROW or extra COLUMN?

If you really wanted that as two rows this would then do that:

Data %>%
    mutate( newdatetime = datetime+minutes(10)) %>%

But there are likely other columns you need to bring with it.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.