Tutorial 1 - Answers.
Tutorial 1 - Answers.
3 March 2023
1. Introduction to RStudio
https://education.rstudio.com/learn/beginner/
chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://cran.r-project.org/doc/
contrib/Paradis-rdebuts_en.pdf
RStudio Layout
(Source: https://datacarpentry.org/genomics-r-intro/00-introduction/index.html)
1
ICT583
3 March 2023
Task 1.1
Generate your first R Script file, plot a histogram for a built-in dataset, save and execute code.
# Loading
data(mtcars)
# Print the first 6 rows
head(mtcars, 6)
# you can also input character for the first argument of the function data()
data("mtcars")
# Print the first few rows, six rows by default
head(mtcars)
# Number of rows (observations)
nrow(mtcars)
# Number of columns (variables)
ncol(mtcars)
str(mtcars)
#> try another dataset
data("iris")
head(iris)
2
ICT583
3 March 2023
# input i for the argument of the function hist(), and store the result as object h
h <- hist(i)
# show values of the plot
h
# you can also input the septal length for the argument of hist()
hist(iris$Sepal.Length)
3
ICT583
3 March 2023
Task 1.2:
R Markdown
Alternatively, you can try creating R Markdown file.
https://rmarkdown.rstudio.com/articles_intro.html
It basically does the same, but also generates a report that embed code with text, outputs, etc.,
in HTML or other file type for reporting.
#>
---
title: "tut1.2"
output: html_document
date: "2023-02-27"
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML,
PDF, and MS Word documents. For more details on using R Markdown see
<http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content
as well as the output of any embedded R code chunks within the document. You can embed an
R code chunk like this:
4
ICT583
3 March 2023
```{r carss}
summary(cars)
str(cars)
```
## Including Plots
plot(pressure)
str(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the
R code that generated the plot.
Discussion:
Can you describe their application task?
- What are the aims of the project?
What data information were presented?
- What are the variables, R functions and results?
Can you summarize any new insights after observing the generated results?
- Did the original authors achieve their goals? How accurate was it?
3. Where to find the publicly available datasets for analysis – explore Kaggle and UCI!
6
ICT583
3 March 2023
Visit the following websites which have the most popular data repository:
https://archive.ics.uci.edu/ml/datasets.php
https://www.kaggle.com/
# Choose one data set that you are most interested in.
# after downloading it onto your drive, you can read it by using an R function e.g., read.csv()
# the first argument of read.csv() should be the directory of your file