[Rd] [R] insert insertRow?
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Fri Jul 21 11:00:54 CEST 2006
[Moved to R-devel, the appropriate list for discussing development of R.]
You can do what you ask for (but micEcon does not provide) more easily and
efficiently by indexing, and learning the power of R's indexing seems an
important part of mastering the tool.
BTW, as a data frame is thought of as like a table in a RDBMS, so very
little you do with one depends on the ordering of rows and columns, both of
which are normally accessed by name.
To insert a row after idx, use something like
NewDF <- OldDF[c(1:idx, idx, (idx+1):nrow(OldDF),]
NewDF[idx+1,] <- value of new row (as a list)
row.mames(NewDF)[idx+1] <- new row name (length-1 character vector)
On Fri, 21 Jul 2006, Marjo en Edwin wrote:
> Dear all,
> In the search for a command to insert a row between other rows in a data
> frame I found that there seems to be no such command in the base R
> package. There is however a very simple function insertRow in the
> micEcon package, that makes use of rbind. I wondered if it would not be
> possible to include the following micEcon functions in the base package:
But insertRow is for a *matrix* and not for a *data frame*, and the former
is a rather easier task.
> Since the functions are already there, I would gather this is not a very
> big effort. It would save people that just want to insert rows and
> columns easily to install another two packages (since micEcon needs
> systemfit) or defining the functions themselves.
> I hope my suggestion will be taken into consideration. Whether it will
> be adopted or not, I still think R is a fantastic statistical package
> that I love to use.
We are concerned about bloat, and also the maintenance load of adding
convenience functions to R. My view is that they are often just another
thing for users to learn and possibly misunderstand, as seems to be the
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel