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 repr oducible ex ample (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
I can't find the InsertRow
function in the R documentation. What package is it from?
pafmax
June 27, 2019, 11:45pm
4
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
system
Closed
July 18, 2019, 11:45pm
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.