The package DT offers an R “window” to JavaScript DataTables. R uses data in matrices’ or data frames’ form; with DT, they can be displayed as tables on HTML pages. The important thing is that filtering, pagination, sorting, etc. are used to transform it into a really useful tool.
Before proceeding, please follow our short tutorial.
Look at the examples given and try to understand the logic behind them. Then try to solve the exercises below using R, without looking at the answers. Then check the solutions. to check your answers.
Exercise 1
Create a basic data table of the iris dataset. HINT: Use datatable()
.
Exercise 2
Create a basic data table of the iris dataset and set the class
to “cell-border stripe”. HINT: Use class
.
Exercise 3
Create a basic data table of the mtcars dataset with the row names displayed.
Exercise 4
Create a basic data table of the mtcars dataset without row names. HINT: Use rownames = FALSE
Exercise 5
Create a basic data table of the first 6 rows of mtcars dataset, but replace row names with the first 6 alphabet letters. HINT: Use rownames = head(LETTERS)
- work with different data manipulation packages,
- know how to import, transform and prepare your dataset for modelling,
- and much more.
Exercise 6
Create a basic data table of the iris dataset, but replace the column names with names of your choice. HINT: Use colnames
Exercise 7
Create a basic data table of the iris dataset, but replace the “Petal. Width” column name with “PW”.
Exercise 8
Create a basic data table of the iris dataset, but change the first column name to ‘ID’.
Exercise 9
Create a basic data table of the iris dataset and add a caption
of your choice. HINT: Use caption
Exercise 10
Create a basic data table of the iris dataset, but add filters in every column top.
Leave a Reply