Adding a new row to the data

Hi all,

I have a dataframe called CAR1_final which is basically made of rows like: "9 1.895850" and so on.

I want to add a row to the 2nd row of my data using InsertRow function, but I receive a warning and an "NA" is produced instead.

Below you can see the commands that I am using:

New=rep(1,1)

CAR1_final=InsertRow(CAR1_final, NewRow = New, RowNum = 2)

Does anyone have any suggestions?

Thanks,

Pouya

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

I can't find the InsertRow function in the R documentation. What package is it from?

Hi, an example would be better, but this is the general way to insert a row in base R to a data frame:

df <- data.frame(A = c(1,2), B = c(3,4))
df[nrow(df) + 1, ] <- c(5,6)

There is a way (with a similarly named function) from the library miscTools to insert a row in a matrix:

m <- matrix(c(1,2), c(2,2), 2)
m <- miscTools::insertRow(m, 3, c(3,3))

Hope it helps