Excluding rows and columns
Sometimes it is necessary to hide or to exclude a particular row or a particular column from a data, so they will not be shown on plots and will not be taken into account in modelling, but without removing them physically. So the excluded rows and columns are still there but are not treated in a usual way by the mdatools methods. In mdatools it is possible by using the following functions:
Function | Description |
---|---|
mda.exclrows(x, ind) |
Exclude (hide) all rows specified by variable ind , which can be a vector
with rows indices, names or a logical vector. |
mda.exclcols(x, ind) |
Exclude (hide) all columns specified by variable ind , which can be a vector
with columns indices, names or a logical vector. |
The mechanism is very simple, the indices of the rows or columns, which must be excluded, are saved into special attributes, which then is recognized by all methods implemented in mdatools
. Standard R functions will ignore the attributes.
Here is a simple example. Let’s create a dataset first (it can be either matrix or a data frame)
Height = c(180, 175, 165, 190, 188)
Weight = c(78, 79, 60, 99, 80)
Shoesize = c(44, 39, 35, 45, 44)
d = cbind(Height, Weight, Shoesize)
rownames(d) = paste0("O", 1:5)
show(d)
## Height Weight Shoesize
## O1 180 78 44
## O2 175 79 39
## O3 165 60 35
## O4 190 99 45
## O5 188 80 44
Now let’s exclude rows 3 and 4 and then column with name “Weight” from the data.
## Height Weight Shoesize
## O1 180 78 44
## O2 175 79 39
## O3 165 60 35
## O4 190 99 45
## O5 188 80 44
## attr(,"exclrows")
## [1] 3 4
## attr(,"exclcols")
## [1] 2
As you can see, all the values are still there, but there are two new attributes, exclcols
and exclrows
. To avoid any issues do not change the values of the attributes manually, always use the functions above.
Now if you make a plot using function mdaplot()
you will see only three points by default, because the other two a hidden. Also plot will be made for columns 1 and 3, because the second column (Weight) was also hidden. See the code and the result below:
You can include the hidden columns and rows back by using mda.inclcols()
and mda.inclrows()
.