Step 1: Installing R and RStudio

Step 2: Getting Started with RStudio

  1. Open RStudio.
  2. Familiarize yourself with the RStudio interface, including the Console, Script Editor, Environment, and Plots panes.

Step 3: Introduction to R Syntax

  1. In the Console, type 2 + 2 and press Enter to see how R performs basic arithmetic.
  2. Try assigning values to variables using the assignment operator <-, for example: x <- 5.
  3. Print the value of x by typing x in the Console and pressing Enter.

Step 4: Introduction to Tidyverse

  1. Install the Tidyverse package by typing install.packages("tidyverse") in the Console and pressing Enter.
  2. (Or install using the ‘Packages’ plane bottom right window)
  3. Load the Tidyverse package by typing library(tidyverse) and pressing Enter.
  4. (Or load Tidyverse using the ‘Packages’ plane bottom right window)
library(tidyverse)

Step 5: Importing Data

  1. Load the built-in iris dataset by typing data(iris) in the Console and pressing Enter.
data(iris)

Step 6: Data Manipulation with Tidyverse

1. Filter the dataset to include only rows where Species is “setosa”:

filtered_data <- iris %>% filter(Species == "setosa")

2. Select only the Sepal.Length and Sepal.Width columns:

selected_data <- iris %>% select(Sepal.Length, Sepal.Width)

3. Create a new column called Petal.Area by mutating the dataset:

mutated_data <- iris %>% mutate(Petal.Area = Petal.Length * Petal.Width)

4. Summarize the dataset to calculate the mean Sepal.Length and Sepal.Width:

summary_data <- iris %>%
  group_by(Species) %>%
  summarise(mean_Sepal.Length = mean(Sepal.Length),
            mean_Sepal.Width = mean(Sepal.Width))

Step 7: Data Visualization with Tidyverse

  1. Use the ggplot() function to create basic plots.
  2. Customize your plots with layers, aesthetics, and themes.
  3. Example: Create a box plot of Sepal.Length for each species:
ggplot(iris, aes(x = Species, y = Sepal.Length)) +
  geom_boxplot()

Step 8: Statistical Analysis

  1. Perform a t-test to compare the Sepal.Length of setosa and versicolor species:
t_test_result <- t.test(Sepal.Length ~ Species, data = subset(iris, Species %in% c("setosa", "versicolor")))
print(t_test_result)
## 
##  Welch Two Sample t-test
## 
## data:  Sepal.Length by Species
## t = -10.521, df = 86.538, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group setosa and group versicolor is not equal to 0
## 95 percent confidence interval:
##  -1.1057074 -0.7542926
## sample estimates:
##     mean in group setosa mean in group versicolor 
##                    5.006                    5.936

Step 9: Save and Share Your Work

  1. Save your R script with the .R extension.
  2. Export your plots as image files or PDFs using the Export button in the Plots pane.