Extract.grouped.data | R Documentation |
Extract or replace subsets of grouped data objects.
## S3 method for class 'grouped.data'
x[i, j]
## S3 replacement method for class 'grouped.data'
x[i, j] <- value
x |
an object of class |
i, j |
elements to extract or replace. |
value |
a suitable replacement value. |
Objects of class "grouped.data"
can mostly be indexed like data
frames, with the following restrictions:
For [
, the extracted object must keep a group
boundaries column and at least one group frequencies column to
remain of class "grouped.data"
;
For [<-
, it is not possible to replace group boundaries
and group frequencies simultaneously;
When replacing group boundaries, length(value) ==
length(i) + 1
.
x[, 1]
will return the plain vector of group boundaries.
Replacement of non adjacent group boundaries is not possible for obvious reasons.
Otherwise, extraction and replacement should work just like for data frames.
For [
an object of class "grouped.data"
, a data frame or a
vector.
For [<-
an object of class "grouped.data"
.
Currently [[
, [[<-
, $
and $<-
are not
specifically supported, but should work as usual on group frequency
columns.
Vincent Goulet vincent.goulet@act.ulaval.ca
[.data.frame
for extraction and replacement
methods of data frames, grouped.data
to create grouped
data objects.
data(gdental)
(x <- gdental[1]) # select column 1
class(x) # no longer a grouped.data object
class(gdental[2]) # same
gdental[, 1] # group boundaries
gdental[, 2] # group frequencies
gdental[1:4,] # a subset
gdental[c(1, 3, 5),] # avoid this
gdental[1:2, 1] <- c(0, 30, 60) # modified boundaries
gdental[, 2] <- 10 # modified frequencies
## Not run: gdental[1, ] <- 2 # not allowed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.