| 42333 |
ripley |
1 |
% File src/library/utils/man/edit.data.frame.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2009 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 27442 |
ripley |
6 |
\name{edit.data.frame}
|
| 56186 |
murdoch |
7 |
\alias{edit.data.frame}
|
| 27442 |
ripley |
8 |
\alias{edit.matrix}
|
|
|
9 |
\title{Edit Data Frames and Matrices}
|
|
|
10 |
\description{
|
|
|
11 |
Use data editor on data frame or matrix contents.
|
|
|
12 |
}
|
|
|
13 |
\usage{
|
|
|
14 |
\method{edit}{data.frame}(name, factor.mode = c("character", "numeric"),
|
|
|
15 |
edit.row.names = any(row.names(name) != 1:nrow(name)), \dots)
|
|
|
16 |
|
| 38092 |
ripley |
17 |
\method{edit}{matrix}(name, edit.row.names = !is.null(dn[[1]]), \dots)
|
| 27442 |
ripley |
18 |
}
|
|
|
19 |
\arguments{
|
| 48876 |
murdoch |
20 |
\item{name}{A data frame or (numeric, logical or character) matrix.}
|
| 27442 |
ripley |
21 |
\item{factor.mode}{How to handle factors (as integers or using
|
|
|
22 |
character levels) in a data frame.}
|
| 43611 |
ripley |
23 |
\item{edit.row.names}{logical. Show the row names (if they exist) be
|
|
|
24 |
displayed as a separate editable column? It is an error to ask for
|
|
|
25 |
this on a matrix with \code{NULL} row names.}
|
| 27442 |
ripley |
26 |
\item{\dots}{further arguments passed to or from other methods.}
|
|
|
27 |
}
|
|
|
28 |
\details{
|
| 33065 |
ripley |
29 |
At present, this only works on simple data frames containing numeric,
|
| 43620 |
ripley |
30 |
logical or character vectors and factors, and numeric, logical or
|
|
|
31 |
character matrices. Any other mode of matrix will give an error, and
|
| 46038 |
murdoch |
32 |
a warning is given when the matrix has a class (which will be discarded).
|
| 27442 |
ripley |
33 |
|
| 43624 |
ripley |
34 |
Data frame columns are coerced on input to \emph{character} unless
|
|
|
35 |
numeric (in the sense of \code{is.numeric}), logical or factor. A
|
| 46038 |
murdoch |
36 |
warning is given when classes are discarded. Special characters
|
|
|
37 |
(tabs, non-printing ASCII, etc.) will be displayed as escape sequences.
|
| 43620 |
ripley |
38 |
|
|
|
39 |
Factors columns are represented in the spreadsheet as either numeric
|
|
|
40 |
vectors (which are more suitable for data entry) or character vectors
|
|
|
41 |
(better for browsing). After editing, vectors are padded with
|
|
|
42 |
\code{NA} to have the same length and factor attributes are restored.
|
|
|
43 |
The set of factor levels can not be changed by editing in numeric
|
|
|
44 |
mode; invalid levels are changed to \code{NA} and a warning is issued.
|
|
|
45 |
If new factor levels are introduced in character mode, they are added
|
|
|
46 |
at the end of the list of levels in the order in which they
|
|
|
47 |
encountered.
|
|
|
48 |
|
| 27442 |
ripley |
49 |
It is possible to use the data-editor's facilities to select the mode
|
|
|
50 |
of columns to swap between numerical and factor columns in a data
|
|
|
51 |
frame. Changing any column in a numerical matrix to character will
|
| 61433 |
ripley |
52 |
cause the result to be coerced to a character matrix. Changing
|
| 27442 |
ripley |
53 |
the mode of logical columns is not supported.
|
| 33065 |
ripley |
54 |
|
| 38042 |
ripley |
55 |
For a data frame, the row names will be taken from the original object
|
|
|
56 |
if \code{edit.row.names = FALSE} and the number of rows is unchanged,
|
|
|
57 |
and from the edited output if \code{edit.row.names = TRUE} and there
|
|
|
58 |
are no duplicates. (If the \code{row.names} column is incomplete, it
|
|
|
59 |
is extended by entries like \code{row223}.) In all other cases the
|
| 61160 |
ripley |
60 |
row names are replaced by \code{seq(length = nrows)}.
|
| 38042 |
ripley |
61 |
|
|
|
62 |
For a matrix, colnames will be added (of the form \code{col7}) if
|
|
|
63 |
needed. The rownames will be taken from the original object if
|
|
|
64 |
\code{edit.row.names = FALSE} and the number of rows is unchanged
|
|
|
65 |
(otherwise \code{NULL}), and from the edited output if
|
|
|
66 |
\code{edit.row.names = TRUE}. (If the \code{row.names} column is
|
|
|
67 |
incomplete, it is extended by entries like \code{row223}.)
|
| 41506 |
ripley |
68 |
|
|
|
69 |
Editing a matrix or data frame will lose all attributes apart from the
|
|
|
70 |
row and column names.
|
| 27442 |
ripley |
71 |
}
|
|
|
72 |
\value{
|
| 41506 |
ripley |
73 |
The edited data frame or matrix.
|
| 27442 |
ripley |
74 |
}
|
|
|
75 |
\author{ Peter Dalgaard }
|
|
|
76 |
\note{
|
|
|
77 |
\code{fix(dataframe)} works for in-place editing by calling this
|
|
|
78 |
function.
|
|
|
79 |
|
|
|
80 |
If the data editor is not available, a dump of the object is presented
|
|
|
81 |
for editing using the default method of \code{edit}.
|
|
|
82 |
|
|
|
83 |
At present the data editor is limited to 65535 rows.
|
|
|
84 |
}
|
|
|
85 |
\seealso{\code{\link{data.entry}}, \code{\link{edit}}}
|
|
|
86 |
\examples{
|
|
|
87 |
\dontrun{
|
|
|
88 |
edit(InsectSprays)
|
| 61160 |
ripley |
89 |
edit(InsectSprays, factor.mode = "numeric")
|
| 27442 |
ripley |
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
\keyword{utilities}
|