The R Project SVN R

Rev

Rev 61168 | Rev 63890 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61168 Rev 62740
Line 1... Line 1...
1
% File src/library/base/man/data.frame.Rd
1
% File src/library/base/man/data.frame.Rd
2
% Part of the R package, http://www.R-project.org
2
% Part of the R package, http://www.R-project.org
3
% Copyright 1995-2010 R Core Team
3
% Copyright 1995-2013 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{data.frame}
6
\name{data.frame}
7
\title{Data Frames}
7
\title{Data Frames}
8
\alias{data.frame}
8
\alias{data.frame}
Line 129... Line 129...
129
  \code{\link{read.table}},
129
  \code{\link{read.table}},
130
  \code{\link{make.names}}.
130
  \code{\link{make.names}}.
131
}
131
}
132
\examples{
132
\examples{
133
L3 <- LETTERS[1:3]
133
L3 <- LETTERS[1:3]
-
 
134
fac <- sample(L3, 10, replace = TRUE)
134
(d <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE)))
135
(d <- data.frame(x = 1, y = 1:10, fac = fac))
-
 
136
\dontshow{% formerly, example was  data.frame(cbind(.,.), fac):
-
 
137
stopifnot(identical(within(d, y <- as.numeric(y)),
-
 
138
		data.frame(cbind(x = 1, y = 1:10), fac)))
135
 
139
}
136
## The same with automatic column names:
140
## The "same" with automatic column names:
137
data.frame(cbind(  1,   1:10),     sample(L3, 10, replace = TRUE))
141
data.frame(1, 1:10, sample(L3, 10, replace = TRUE))
138
 
142
 
139
is.data.frame(d)
143
is.data.frame(d)
140
 
144
 
141
## do not convert to factor, using I() :
145
## do not convert to factor, using I() :
142
(dd <- cbind(d, char = I(letters[1:10])))
146
(dd <- cbind(d, char = I(letters[1:10])))
143
rbind(class = sapply(dd, class), mode = sapply(dd, mode))
147
rbind(class = sapply(dd, class), mode = sapply(dd, mode))
144
 
148
 
145
stopifnot(1:10 == row.names(d))  # {coercion}
149
stopifnot(1:10 == row.names(d))  # {coercion}
146
 
150
 
147
(d0  <- d[, FALSE])   # NULL data frame with 10 rows
151
(d0  <- d[, FALSE])   # data frame with 0 columns and 10 rows
148
(d.0 <- d[FALSE, ])   # <0 rows> data frame  (3 cols)
152
(d.0 <- d[FALSE, ])   # <0 rows> data frame  (3 named cols)
149
(d00 <- d0[FALSE, ])  # NULL data frame with 0 rows
153
(d00 <- d0[FALSE, ])  # data frame with 0 columns and 0 rows
150
}
154
}
151
\keyword{classes}
155
\keyword{classes}
152
\keyword{methods}
156
\keyword{methods}